-
-
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
--no is bugged with default arguments #2068
Comments
Thanks for the example code. You are missing the description argument in your example, so the Try:
No, it is a built-in feature which can not be disabled. (I think you can flip the results by specifying both a default value and a preset value, but I suggest it is not worth the effort!) |
Sorry about that. With the following program: const { program } = require('commander');
program.option('--no-foo', 'foo description', true)
program.option('--no-bar', 'bar description', false)
program.parse();
const options = program.opts();
console.log(options) I get the following output:
However, as I said above, this output is a bug. Consider the following line: program.option('--no-foo', 'foo description', true) When translated to English, this line means: "By default, we want there to be no foo."
I understand that Commander.js has magic behavior to transform |
Here is another way of describing it. Adding an option with flags I see your interpretation, but it isn't the only interpretation and I don't think is worth considering changing the behaviour. Not least because specifying a default value for a negated option is probably rare. |
Ok, I will close this issue, thank you. In the future, a way to disable the magic behavior would be welcome, I see that it was also previously requested here: #979 |
Hello, and thanks for the useful library.
Consider the following program:
Running this program will result in the following output:
This is a bug, because commander.js is not using the default value that was specified. Specifically, I would expect specifying
true
for the default value of--no-foo
would mean thatfalse
should be the default value of--foo
, which means that the correct output should be:Additionally, I will say that I do not like the special/magic behavior of commander.js to invert my
--no
arguments. It makes for a more confusing code base, especially when bugs like the above exist! Is there some way to disable this special/magic behavior?The text was updated successfully, but these errors were encountered: