commander.js icon indicating copy to clipboard operation
commander.js copied to clipboard

There seems to be a bug when having a parameter called "name"

Open akayami-legacy opened this issue 9 years ago • 1 comments

Considering following code:

const program = require('commander');
program
	.version('0.0.1')
	.option('-n --name [name]', 'Specify name of this vhost')
	.option('-p --port [port]', 'Specify port')

program.parse(process.argv);

console.log(program.name)
console.log(program.port)

If I execute: node bug2.js -n a -p b I get response:

a
b

However, if I execute: node bug2.js

I get:

[Function]
undefined

Is there a safe way to check which parameter was provided ? This burned me on just checking:

if(program.name) {
...
}

akayami-legacy avatar Aug 20 '17 12:08 akayami-legacy

Duplication of #284, which is similar to #680, #105. Closed. Keep your eyes on #105 issue, thx

segfaultmedaddy avatar Aug 20 '17 12:08 segfaultmedaddy