Open Arthelon opened 8 years ago
I would also love to use this feature. Faced this issue when trying to specify API version using number wrapped in brackets like "1.0"
. It got converted to number 1
.
Same for me. Is there any workaround? I'm having problems with hex strings such as:
"0x4e47e95247a535d9c1ed9e5a73f1344a5d864383"
Being converted to a number:
4.469049581943643e+47
The only alternative is to use a type
with an option
but this is a little awkward for the CLI I'm working on.
The conversion seems to be from the dep minimist
here:
https://github.com/dthree/vorpal/blob/master/lib/util.js#L33
And via minimist, anything not flagged with an option flag that may be a number according to the regex is converted:
https://github.com/substack/minimist/blob/master/index.js#L186
maybe arguments that are quoted should be passed as strings, at least.
Hello again dear contributors.
@dthree, I'm ready to implement this feature/bugfix and I was wondering if you would be willing to accept my contribution. If you would, please share your opinion on this issue and maybe give some guidelines if you think this issue makes sense.
Thank you! :)
Greetings to everyone having this issue.
I've discovered a way to make params be parsed as strings. Hopefully this will be useful to someone. Note: This enables such behavior per-command and parses ALL arguments(non-options) as strings.
So the solution is - add "_"
to your string
types by calling .types({string: ['_']})
.
This has to be done PER-COMMAND for those commands in which you want arguments to be parsed as strings.
Examples:
If you already have .types()
call add "_"
to its "string":
Before:
vorpal
.command('send <number> <message>')
.option('--anotherNumber <val>')
.types({string: ['anotherNumber']})
After:
vorpal
.command('send <number> <message>')
.option('--anotherNumber <val>')
.types({string: ['anotherNumber', '_']})
If you don't have .types()
call, make new one with "_"
in "string":
Before:
vorpal
.command('send <number> <message>')
After:
vorpal
.command('send <number> <message>')
.types({string: ['_']})
@dthree Any plans to fix this issue ?
Command arguments are automatically assigned a type but there doesn't seem to be any support for explicit typing like with options. When entering in a phone number with special characters like so:
the argument "number" is converted to a number, omitting the + symbol. Furthermore, I think the .types() function available for options should also support command arguments.