yargs: Conflicting options with default values (or boolean values)
Using conflicts
with an option that has a default value, or a boolean option (which is automatically set to false
even if a default value is not provided) always throws an error, because the conflicting option name will always be defined.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 25 (5 by maintainers)
I ran into a similar issue, and what fixed it for me was changing defaults to undefined…
note above, without
default: undefined
I kept having the “arguments are mutually exclusive” problemI’m running into this issue as well; it makes it impossible to have mutually exclusive options where one or both are booleans.
@bcoe what I would expect is that if the argument is a boolean, it only considers it “set” if it’s
true
. Similarly, conflicts should be checked before default values are applied.This issue is solved now for booleans: a conflict will be triggered only if you explicitely set a default value (as for other types).
sure, my code is basically:
No, sorry, I haven’t made any progress on this. I worked around it by just not using defaults for booleans, and then forgot to look into it beyond the comments above.
Just ran into this bug now.
For now, I’m setting
coerce: (v) => v || undefined
on the boolean flag that’s causing the problem as a workaround.@jordansexton any thoughts about what the default behavior should be … what’s weird is that
false
is a value it feels like it would be too loose to have the conflicts logic simply look for a falsy value since values like""
would also pass the conflicts test.