-
Notifications
You must be signed in to change notification settings - Fork 118
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
Do not set boolean to false
if flag is not in args
#116
Comments
You already have this capability if you don't like the default processing of booleans. Add |
Yes. However it feels like a workaround.
That would avoid to use the workaround of filtering out properties that are undefined. |
IMO, don't believe default behavior should be to create a third value, |
The objective of In the context of a CLI, a flag (as in a parameter without value like
So the fact that |
Look, I totally understand what you're trying to do -- just disagree with changing what is known as default processing for everyone. However, it seems to me as though you'd have the same problem for all types, not just boolean, wouldn't you? Maybe use the config file to create the default values for the CLI processing (use output of first It's definitely using |
I don't know, it seems you are trying to find every possible reason to push back on this proposal. If you disagree and in your opinion it's a bad idea, that's alright.
No, for all other types With this proposal
It seems to be a really complex workaround. At least way more complex than filtering out the
It doesn't matter here. The use case mentioned is to merge the
I don't really get what's the point of this remark. This proposal is exactly the opposite of hardcoding, as it propose to not hardcode the default value of |
Well, I have no research to back me up, but your implemented proposal would likely break all packages depending on That said, I have no problem at all with having a
Perhaps I wasn't clear. When I said "hardcoded app-defaults", I meant those of the application itself, passed via |
How does this break the trivial falsey check ( Even if folks are doing non-coercive comparison of these properties, bump the major and done. Nobody gets broken, everyone is happy. (The strict comparison would only be useful to distinguish a literal |
@evocateur Never said it would break trivial false checks, but I don't know if everyone's code processes cli options coercively. I advocated implementing the feature using a yargs-parser configuration option that wouldn't break anyone's code regardless. Your problem with that is what exactly? |
I guess I just like publishing breaking versions instead of forcing config to fix a fundamentally wrong choice. Must be a moral failing on my part, I’m sure.
… On Mar 23, 2018, at 07:59, P. Roebuck ***@***.***> wrote:
@evocateur Never said it would break trivial false checks, but I don't know if everyone's code processes cli options coercively. I advocated implementing the feature using a yargs-parser configuration option that wouldn't break anyone's code regardless. Your problem with that is what exactly?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@pvdlg, looks like |
Regarding the boolean definition comment above; every enum for non-required user-supplied values always needs an additional option for “not provided” - this doesn’t make it not a boolean. The arg is a boolean, when provided, but the property on argv need not be. |
@ljharb @evocateur @plroebuck sorry, managed to miss a fairly heated discussion about default boolean values it turns out. I don't have a super strong opinion, as @evocateur points out |
Currently when defining a
boolean
option, without specifying its default value, if the user doesn't set the corresponding arg the value is set tofalse
.Therefore its impossible to know if users set the flag to
false
or this they just omitted it.This is problematic in situation in which you want to merge the options returned by
yargs-parser
with another object options (from a config file for example) withObject.assign
or similar.Typically you would merge options so the CLI args take precedence over the config file. So users can specify their config and override it in development mode by passing an option to the cli.
In such situation, if the user do not pass the flag in the CLI, the merged options will always have
false
for this flag, asyargs-parser
option have it set to false and it override what's in the config.Ideally the value of a boolean flag should be
undefined
when the user doesn't pass the flag in the CLI.Would be open to a PR that implement such behavior?
The text was updated successfully, but these errors were encountered: