-
-
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
passThroughOptions with command #1461
Comments
Good description, thanks. This is intended behaviour, but is a little subtle. The work-around is to also specify (If that is unclear, I can write some examples. It is late here so I am doing a quick reply!) |
Will be better if you can give some examples. Also in this example, you are using |
I will post some more examples here for comment. |
If your subcommand does not have any of your own options, you could just allow unknown options: const { program } = require('commander');
program.enablePositionalOptions();
program
.command('prettier')
.description('runs prettier')
.allowUnknownOption()
.action((options, cmd) => {
console.log(`Running: ${cmd.args.join(' ')}`);
});
program.parse();
|
If your subcommand may have your own options at the start of the arguments, you can use const { program } = require('commander');
program.enablePositionalOptions();
program
.command('prettier')
.description('runs prettier')
.option('-p, --prompt <value>', )
.passThroughOptions()
.allowUnknownOption()
.action((options, cmd) => {
const prompt = options.prompt || 'Running';
console.log(`${prompt}: ${cmd.args.join(' ')}`);
});
program.parse();
|
And what if I have a cli command like this: |
nvm, I saw you answer it @ #1229 |
@pluqueTheLuxe
|
An answer was provided, and no further activity in a month. Closing this as resolved. I will be watching to see if more people confused that Feel free to open a new issue if it comes up again, with new information and renewed interest. |
Trying to use
passThroughOptions
withcommand
Code:
Using as
node <path_to_file> prettier --write .
Error
error: unknown option '--write'
What's working
node <path_to_file> prettier -- --write .
Output:
Running: prettier -- --write .
--
should not be required to make it work as passThroughOptions is usedReferences used: https://github.com/tj/commander.js/blob/master/examples/pass-through-options.js
https://github.com/tj/commander.js/blob/master/examples/positional-options.js
The text was updated successfully, but these errors were encountered: