Skip to content

Handling of "--version" program option is buggy #1252

@khitrenovich

Description

@khitrenovich

Program option -v/--version is not supported in reliable way.

Consider the following sample program:

const app = require('commander');

app
  .option('-v, --version [id]', 'version identifier to use (optional)')
  .action((options) => {
    console.log(options.version);
  });

app.parse(process.argv);

This will be the output -

~/work/commander-test > node app.js --version 42
42
~/work/commander-test > node app.js 
[Function: version]
~/work/commander-test > 

Note that options.version is always defined, even if not provided, defaulting to a function (my guess that it is https://github.com/tj/commander.js/tree/v5.0.0#version-option).

Side effect of the above is that I cannot mark -v option as required - it does not error out, since it is always implicitly defined.

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