-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
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
Labels
No labels