-
-
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
Implicit value for command options #1595
Comments
I think you have something else in your code, as program.addOption(new Option('--watch', 'some description...'));
program.parse();
console.log(program.opts());
No, not currently.
This might be what you are waiting for: #1587 |
Wow either the universe has aligned or that feature was really high in demand :D Side note: What's the ETA on that entire round getting merged to master? |
#1587 will go in a feature release and does not require a major release. Probably fairly soon. Like weeks, not months. |
Say I have the following command option:
(The style in which the option doesn't take an argument itself)
If I don't specify the
--watch
option when running the command, it returnsoption: false
whereas a better value IMO would've beenwatch: undefined
which is falsy enough but also gives us a hint as to whether or not this option was explicitly false or implicitly false.I understand that this philosophy wouldn't work for negatable options since in that case
undefined === implicit true
which would be odd since undefined is falsy.Is there a way to tell whether or not an option was explicitly set or implicitly?
Bit of context:
I have a command that takes in the option mentioned in the example above, but also can check for the same "flag" in the
process.env
.Now if the option flag has been explicitly set, I'd ignore the environment variables, since it's a direct override from the shell. However if the option is not explicitly set I'd like to use the environment variables as backup.
Problem is: by not explicitly adding watch returns
false
and there's nowhere to find out whether it was explicitly set or implicitly other than maybe traversing through the process args by hand and seeing if the flag is present.The text was updated successfully, but these errors were encountered: