Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number out of precision. #23

Open
tvrcgo opened this issue Jun 2, 2018 · 5 comments
Open

Number out of precision. #23

tvrcgo opened this issue Jun 2, 2018 · 5 comments

Comments

@tvrcgo
Copy link

tvrcgo commented Jun 2, 2018

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. :)

@egoist
Copy link
Collaborator

egoist commented Jun 2, 2018

what if cli.option('n', { type: 'string', desc: 'something' }) ?

@tvrcgo
Copy link
Author

tvrcgo commented Jun 2, 2018

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.

@egoist
Copy link
Collaborator

egoist commented Jun 2, 2018

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.

@tonyxiao
Copy link

Minimist is no longer a dependency it seems and the issue is still happening

@MaikuMori
Copy link

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants