Skip to content

[BUG] Help output broken for options with falsy default values #855

@plroebuck

Description

@plroebuck

Description

Help output for options with falsy default values don't show up.

Steps to Reproduce

Save the following script as "commander.spec.js".

#!/usr/bin/env node
var program = require('commander');

function list(val) {
  return val.split(',');
}

program
  .option('-s, --str [value]', 'Specify string value', String, '')
  .option('-l, --list [items]', 'Specify list items', list, [])
  .parse(process.argv);

Make the script executable and invoke it as follows to display help.

$ chmod ugo+x commander.spec.js
$ ./commander.spec.js --help

Expected Behavior

  Usage: commander.spec [options]

  Options:
    -s, --str [value]               Specify string value (default: '')
    -l, --list [items]              Specify list items (default: [])
    -h, --help                      output usage information

Actual Behavior

  Usage: commander.spec [options]

  Options:
    -s, --str [value]               Specify string value (default: )
    -l, --list [items]              Specify list items (default: )
    -h, --help                      output usage information

Version Information

  • OS: macOS 10.13.6 (but verified elsewhere as well)
  • Shell: bash
  • Node: v10.3.0
  • Transpiler: N/A

Additional Information

Where

Command.prototype.optionHelp

Affected releases

v2.12.0 through current (v2.17.1).

Applicable Issues

#122
mochajs/mocha#3433

Metadata

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