Open DRSDavidSoft opened 5 years ago
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
8081
app.js
8080
Currently, I am forced to handle the flag values without the built-in default value parameter, i.e.:
default
.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 :)
args
Can I suggest implementing any of these methods, please?
Either:
args.setOpt(args.STRICT, true)
args.setStrict(true)
args.strictType = true
preferred method
.option('port', 'foo bar', 8080, null, { strict: true })
$ 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 :)
Feature Request
I would like my program to throw an error if the user tries to enter something other than an integer, e.g.:
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 to8081
app.js
which leaves it at8080
Workaround
Currently, I am forced to handle the flag values without the built-in
default
value parameter, i.e.:becomes:
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
Example
I hope you would consider this, thanks :)