a more powerful option parser for node.js
If you're looking for documentation, please refer to the wiki.
Why another option parser?
Because I'm tired of using option parsers that don't do their jobs very well. Nearly every parser I've used has required either a workaround to actually make it work, or boilerplate code that's off-putting (at least, for some developers). In short: untraditional implementations and poor abstractions.
Take optimist and yargs, for example: both of them are great parsers in their own right, but they provide no method or abstraction for handling arguments in the order in which they appear on the command-line.
Instead, the way I've seen most people use both of these excellent parsers inherently makes their programs handle args in the order in which they are handled:
#!/usr/bin/env node// ex.js// an example of optimist in actionvar args =argv;if argsvconsole;process;if argshargs;process;
-v is handled before
-h; so even if you run
node ex.js -h -v, the version string will always get printed instead of the expected usage information.
In optimist, the problem can sort of be resolved by looping over the resulting
args object using
Object.key like so:
#!/usr/bin/env node// ex.js// an example of optimist in actionvar args =argv;// doesn't capture commands// can also be done in a really ugly way like so:// Object.keys(args).slice(Object.keys(args).indexOf('$0') + 1)Object;