cac
cac copied to clipboard
Number out of precision.
I passed a number out of precision:
cli -n 1002822319600013312
got n = 1002822319600013300, a number
cli -n "1002822319600013312"
also got n = 1002822319600013300, a number
May be better to parse parameter as string first and auto convert to number if within precision. :)
what if cli.option('n', { type: 'string', desc: 'something' })
?
I use cli.command
to init command and type
is not working.
like this:
node bin/cli.js destroy 1002822319600013312
destroy a record by id.
I think it's a minimist issue, related to this line: https://github.com/substack/minimist/blob/4cf45a26b9af5f4ddab63107f4007485e576cfd3/index.js#L186
For a workaround, you can use process.argv[3]
directly.
Minimist is no longer a dependency it seems and the issue is still happening
If you use something like:
cli
.command("<...strings>", "strings")
cli.ts 123 123 123
You'll get ["123","123","123"]
But if you add
cli
.command("<...strings>", "strings")
.option("-j, --json", "Output as JSON")
cli.ts --json 123 123 123
It sets strings to:
[123, "123", "123"]
This whole auto-conversion by guessing needs to go. Args are strings unless explicitly declared otherwise.
minimist
has the same issue and it's so annoying. I believe deno flags too.
In this specific example there is no big problem since I could convert it back. The real problem is when args are long strings like package numbers that look like numbers, but as soon as you auto convert them the data is lost because JS can't handle so big "numbers".