Wednesday 26 April 2017

Node.js: Command line parsing with mutually exclusive arguments

I thought this should exist but it doesn't seem to be supported in any of the popular command line args parsing libraries.

I want my script to have a set of options that are exclusive of another option.

For example, here I use the -c option

$ node my_script.js -c "foo"

But here, the -c options doesn't make sense because I specified some different options.

$ node my_script.js -b "bar" -n 5

The following should be an error because -c is mutually exclusive to -b and -n

$ node my_script.js -b "bar" -n 5 -c "foo"

I know this exists in Python's argparse. I'm surprised I can't find it in the Node world.



via Sean Lynch

No comments:

Post a Comment