-
-
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
requiredOption
doesn't behave properly with default value
#1135
Comments
I considered default values when I was implementing The use case I came up with that persuaded me to keep default value is:
I particularly like this as an elegant combination of (For interest, a different but closely related issue got opened just yesterday: #1130. I'll be keeping an eye on how much confusion the current behaviour causes.) |
If
So no option - program doesn't run, option without value - use the default, option with value - use the value. |
By design and as documented, The behaviour you describe is what you might think happens for option with an
but in fact the default value is assigned when the option is not supplied, as before! That behaviour does not seem particularly useful , but it has always been like that so would be a big breaking change. |
An answer was provided, and no further activity in a month. Closing this as resolved. Feel free to open a new issue if it comes up again, with new information and renewed interest. |
For interest, I noticed a similar issue against |
PR #1652 adds program
.addOption(new Option("-p --path [string]", "glob pattern of files/folders to delete")
.preset("../*")
.makeOptionMandatory()); |
The code
will run without the
-p
option set (because technically it has a value, default, but still) and delete whatever../*
resolves to.I think
requiredOption
should either:node program.js
won't run butnode program.js -p
will run withprogram.path == "../*"
and of coursenode program.js -p /some/path/*
will run withprogram.path == "/some/path/*"
The text was updated successfully, but these errors were encountered: