Last active
December 12, 2016 08:49
-
-
Save iredchuk/ab253c68a880d45e0ab99d853fc56ddc to your computer and use it in GitHub Desktop.
commander option vs args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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