-
Notifications
You must be signed in to change notification settings - Fork 106
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
Allow for unknown options #25
Comments
yes, it's a good question and something other option parsers do.. however, it just doesn't work with this parser.. in particular, it clashes with the
and have this command line scenario:
then
then what should happen? Is However, i will have a think about it for a future version. It maybe possible to allow unknown options in certain cases (e.g. if no |
Thanks for the quick response! There are multiple ways of doing this. minimist has one approach. I do agree that default causes problems and because of this, we may need to change how unknown works depending on the mode of default or some other parameter. For example: To give a concrete use case: I am trying to write a wrapper around another CLI library. I want to do something like It's clear an implementation of this could have a lot of corner cases. |
I have the same issue. It would be nice if we can just skip the unknown parameters. |
I've implemented a first pass at this feature (partial parsing), it's currently in beta.. to accept unknown options you now pass so, to use your example, if we had this script... const commandLineArgs = require('command-line-args')
const definitions = [
{ name: 'foo', type: String },
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'libs', type: String, defaultOption: true }
]
const options = commandLineArgs(definitions, { partial: true })
console.log(options) ... and we installed it as
... would output this: { foo: 'bar',
verbose: true,
libs: 'libfn',
_unknown: [ '--libarg', 'val1', '-r' ] } The big changes here are that the script no longer throws with Please install the beta and let me know what else needs to happen: $ npm install command-line-args@^4.0.0-0 I'm considering making |
Fixed and released in v4.0.0. |
Awesome! |
Would it be possible to allow for unknown options and pass them back in a dict? Something similar in python: https://docs.python.org/dev/library/argparse.html#partial-parsing
The text was updated successfully, but these errors were encountered: