Skip to content

Instantly share code, notes, and snippets.

@iredchuk
Last active December 12, 2016 08:49
Show Gist options
  • Save iredchuk/ab253c68a880d45e0ab99d853fc56ddc to your computer and use it in GitHub Desktop.
Save iredchuk/ab253c68a880d45e0ab99d853fc56ddc to your computer and use it in GitHub Desktop.
commander option vs args
const cmd = require('commander');
cmd.option('--foo', 'foo option');
cmd.parse(process.argv);
console.log('[foo]', cmd.foo);
console.log('[args]', cmd.args);
// $ node index --foo bar
// [foo] true
// [args] [ 'bar' ]
// $ node index bar --foo
// [foo] true
// [args] [ 'bar' ]
// $ node index bar foo
// [foo] undefined
// [args] [ 'bar', 'foo' ]
// $ node index foo bar
// [foo] [ 'bar' ]
// [args] [ 'bar' ]
// ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment