-
-
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
Optional type and Custom option processing do not work together #1201
Comments
I expect you are looking for a more sophisticated solution, but I'll point out there is a simple manual approach to handling the default value in the README:
|
(On a historical note the default value in this case is being treated the same way as for an option with a required value, rightly or wrongly, and has been that way since the beginning: |
I had been wondering whether the custom option processing function should be called when there is no value for an optional flag. This would allow more complex handling like in the original post in this thread, but I realised today would break the use of simple coercion routines.
The current behaviour is calling the program like |
An approach was provided, and no further activity in a month. I have had a look at the code history, and discounted one possible code change. There is not likely to be further action due to this report. Feel free to open a new issue if it comes up again, with new information and renewed interest. Thank you for your contributions. |
I discovered recently that options with optional arguments are actually broken when there is a default value, making the requested behaviour difficult to achieve. The option is ignored when supplied without a value. I have PR #1652 open to fix that, and add program
.addOption(new Option('-w, --with-cheese [value]', 'Use something special').preset('cheddar')); |
Opening a new issue exactly the same as #984.
I have a use case for a where I would like a flag with an optional value, however instead of the flag being
true
I want to evaluate it to a default value.Ideally the following would happpen:
That seems like it could lead to unexpected and ambiguous results though. So the next best thing, and how i immediately thought to handle it, was with custom option processing:
However given the details in #984, this doesn't work either. I'm investigating the event listener, but I can't/don't want to store something outside of the normal options, meaning I need to update the command so that
program.withCheese
ANDprogram.opts().withCheese
reflect the value appropriately. I have yet to figure that out...The text was updated successfully, but these errors were encountered: