-
-
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
allowUnknownOption
handling in .parseOptions()
#1945
Comments
I opened #1946 with an implementation of this suggestion. |
In
The arguments across those last two categories are kept in order. In internal use, they get passed into the subcommand for further processing. import { program} from 'commander';
program.option('--global');
program.command('sub')
.option('--known');
const exampleArgs = ['--global', 'sub', '--known', '--unknown', 'sub-arg'];
console.log(program.parseOptions(exampleArgs));
|
In #1944 (comment), you said:
But despite
The
They still are in #1946, it's just that the switch from
They still do in #1946 (see the last part of the previous sentence). |
I basically don't understand what your real concern is. I'll add a couple more explanations. The docs says:
The point of the comment is that people might think the unknown options get auto-detected or put somewhere else. They just get returned in import { program} from 'commander';
program
.allowUnknownOption()
.option('--known');
program.parse();
console.log(`opts: %o`, program.opts());
console.log(`args: %o`, program.args);
Do you have a suggestion for a better wording?
My recollection is I wrote that test to capture a specific error case I encountered where I felt the default behaviour would not give the best information to the end-user and I customised the outcome (and wrote a test because it was on purpose). |
I agree the It looks like there aren't any visible changes left (at least if we ignore the fact that
A late addition: You also said this in a comment above:
But there is no processing required for unknown options found before a subcommand when using I realize this is a very small and subtle technical detail, so the change is hard to “sell”, but I hope I still managed to convince you it is worth it. If so, please consider reopening #1946 (click here to see all the implied file changes). If not, feel free to ask for further clarification or close the issue. |
I have just published feature/parseOptions-rework combining the changes from #1934 and #1946 into one big |
I had a reread of #1946, and looked at the combo branch, and reread the extensive reasoning multiple times. Not convinced, sorry.
Closing the issue! |
The docs says:
However, unknown options are not treated as command-arguments by
.parseOptions()
whenallowUnknownOption
is used. That can be shown by a simple example:This might seem harmless, but actually has consequences. The following test from
tests/command.helpCommand.test.js
, line 24 would have to fail if unknown options were treated as described in the docs sincecaughtErr.code
would equal to'commander.unknownCommand'
instead of'commander.help'
.Some possible solutions I see:
.parseOptions()
as suggested by the docs and.unknownCommand()
treat options speciallyThe text was updated successfully, but these errors were encountered: