Skip to content

Init value of option '--name' is a [Function] #648

Closed
@bySabi

Description

When a option --name is not set on CLI, initial value is a [Function]

Example:

var Command = require('commander').Command;
var program = new Command('my-cli');

program
  .version('0.0.1')
  .option('--name <name>', 'Set name')
  .option('--name-prefix <name>', 'Set prefix name')
 .parse(process.argv);
  })
...

console.log('name: ' , program.name)
console.log('namePrefix: ', program.namePrefix)

The ouput of $ my-cli --name-prefix=test is:

name: [Function]
namePrefix: test

Here name should be undefined

The ouput of $ my-cli --name=test is:

name: test
namePrefix: undefined

Here is ok!

IMHO a widely use option like '--name' that collide with [Command.name] should have a dedicated check and initialization branch in code.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions