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

Feature: Strict type parsing mode #133

Open
DRSDavidSoft opened this issue Jan 31, 2019 · 0 comments
Open

Feature: Strict type parsing mode #133

DRSDavidSoft opened this issue Jan 31, 2019 · 0 comments

Comments

@DRSDavidSoft
Copy link

Feature Request

I would like my program to throw an error if the user tries to enter something other than an integer, e.g.:

app.js --port NOT_AN_INT

should return an Exception instead of falling back to the default.

Everything works great on either:

  • app.js --port 8081 which sets the port flag to 8081
  • app.js which leaves it at 8080

Workaround

Currently, I am forced to handle the flag values without the built-in default value parameter, i.e.:

  .option('port', 'foo bar', 8080)

becomes:

  .option('port', 'foo bar')

That way, I can validate the flag value myself, which is suboptimal. I would've preferred if args would take care of that for me, too :)

Possible new feature

Can I suggest implementing any of these methods, please?

Method A (Global options)

Either:

  • args.setOpt(args.STRICT, true)
  • args.setStrict(true)
  • args.strictType = true

Method B (Per-flag)

preferred method

  .option('port', 'foo bar', 8080, null, { strict: true })

Example

$ app.js --port abracadabra
User error: please enter a valid number for the `port` argument.

$ app.js --port 8081
app.js: Ready, port 8081 was accepted.

I hope you would consider this, thanks :)

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

No branches or pull requests

1 participant