Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
khitrenovich opened this issue Apr 21, 2020 · 3 comments
Closed

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

khitrenovich opened this issue Apr 21, 2020 · 3 comments

Comments

@khitrenovich
Copy link

khitrenovich commented Apr 21, 2020

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.

@shadowspawn
Copy link
Collaborator

Clashing option names with properties on the Command object is a problem, with collected issues in #933

The good news is there is a solution now! See .storeOptionsAsProperties(false) and the section in the README:

https://github.com/tj/commander.js#avoiding-option-name-clashes

@khitrenovich
Copy link
Author

Thank you, this solves the problem for me!

@shadowspawn
Copy link
Collaborator

Opened a PR to add a warning for option name clashes: #1275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants