-
-
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
Weird allowUnknownOption behavior #609
Comments
@kevinrenskers I am no nodejs developer, but if i look at these test cases in the commander repo (https://github.com/tj/commander.js/blob/master/test/test.command.allowUnknownOption.js) my impression is that you misinterpret the meaning of You seem to think/hope that it means that all and any parameter will be parsed. The test cases tell me that including that method call will instead only prevent commander from generating errors in case it encounters arguments that were not configured and thus expected. |
That is indeed what I am hoping for :) Also what the answer to #426 seemed to imply. |
I may be way out of my league here, but i wonder if the path you intend to go down truly meets your use case. Do you really want people to specify theme specific options on the command line, along with the options/arguments that drive the core conversion? They feel like two different concerns to me. Personally i would be more comfortable with a single, optional argument that allows me to point to a config file. Something like:
That way the command line remains concise whilst a theme designer can go wild with theme driving settings. I could imagine a config file to look like:
This also spares you from having to figure out how to properly encode the command line arguments in case they contain fancy characters and complex objects. |
Not a bad idea, but I feel like that just puts the burden on the end user of the tool. Instead of just quickly firing off a command they'd now have to create a config file. It would be awesome if Commander would work as I described in the issue above, I feel that it does make sense that unknown options are still parsed into So at least partly it feels like a bug, and partly like a feature request. |
+1, is there a way to retrieve the unknown options? |
In the end I switched to |
Thank you for the tip, unfortunately I'm editing a file for a PR so I can't remove their usage of Commander... I think I would parse with a regex the --flags |
There is a caller work-around. I had tried a pattern I had seen in another program of using bare "--" to stop processing options and leave them for subcommand. I found it worked in commander too, and am using this technique. See comments in #216 program
.command("test <command> [args...]")
.option("--expected")
.action((command, args, options) => {
console.log(`expected is ${options.expected}`);
console.log(`command is ${command}`);
console.log(`args is ${args}`);
|
Been using commander for a cli project and it's nice project, but possibly will drop it due to what @kevinrenskers described here. The |
This issue has not had any activity in over six months. It isn't likely to get acted on due to this report. The current Feel free to open a new issue if it comes up again, with new information and renewed interest. Thank you for your contributions. |
Note: from Commander 5 unknown options are passed through as command arguments, as per the original comment here. |
I'd like to allow any and all options, because my application has plugins that can support their own options that my code itself doesn't know about. I just want to pass on all options as given to plugins, and they pick the ones they know about (hope this makes sense so far).
Sadly
allowUnknownOption
doesn't work as I expected, and I was wondering if this is a bug, or am I missing something?When I run this with
node test.js --foo bar
then I would expect thatprogram.args
would contain the foo option with the bar value, but insteadprogram.args
is empty.Only when I run the script like
node test.js foo bar
, thenprogram.args
contains two values. So it seems that unknown options can't be supplied with the--
prefix, which means they don't fit well with the "regular" options that my application itself supports, and that plugins can't really expect to get key/value pairs?At the moment it seems like plugins would need to re-process the
program.rawArg
themselves using Commander with their own explicitly configured options, which is a shame to explain to my plugin authors.The text was updated successfully, but these errors were encountered: