-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
version 5, allowUnknownOption(true) not work #1278
Comments
The behaviour did change in v5, but working in my test. What did you type on command line, and what is not working? const { program } = require('commander');
program
.command('build [taskfile]')
.description('build the application')
.option('--config [string]', 'path to configuration file for activities build')
.option('--debug [bool]', 'enable debug log or not')
.option('-d, --deploy [bool]', 'run deploy activity')
.allowUnknownOption(true)
.action((taskfile, cmd) => {
console.log('args:', cmd.args);
console.log('opts:', cmd.opts());
});
program.parse(); $ node index.js build --config aaa --unexpected
args: [ '--unexpected' ]
opts: { config: 'aaa', debug: undefined, deploy: undefined } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I just noticed your example code checks |
@shadowspawn xxx build --deploy --setversion=1.1.0 will get --setversion=1.1.0 as taskfile |
Yes. The const { program } = require('commander');
program
.command('build <taskfile>')
.description('build the application')
.option('--config <string>', 'path to configuration file for activities build')
.option('--debug', 'enable debug log or not')
.option('-d, --deploy', 'run deploy activity')
.allowUnknownOption(true)
.action((taskfile, cmd) => {
console.log('taskfile: ', taskfile);
console.log('args: ', cmd.args);
console.log('opts: ', cmd.opts());
});
program.parse(); $ node index.js build --deploy NAME --setversion=1.1.0
taskfile: NAME
args: [ 'NAME', '--setversion=1.1.0' ]
opts: { config: undefined, debug: undefined, deploy: true } A couple of other optional suggestions for your example program:
|
An answer was provided, and no further activity in a month. Closing this as resolved. Feel free to open a new issue if it comes up again, with new information and renewed interest. |
version 5, allowUnknownOption(true) not work.
eg.
The text was updated successfully, but these errors were encountered: