fix(count): do not increment a default value #39
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on yargs/yargs#500
This was a bit tricky to figure out because default values were already being applied in line 274 but were then being overwritten immediately thereafter in a weird attempt to use the
increment
function to set a default value of 0 when no explicit default value is given. When an explicit default value was given, theincrement
function would then inadvertently add/concat a1
to the value. 😕Therefore the fix is comprised of these changes:
applyDefaultsAndAliases
do its job of setting explicit defaults, see line 2740
to a count only when (a) no arg is given and (b) no explicit default is set, see new line 278increment
function when a count arg is actually given (not when setting a default value), see new line 339increment
and don't wrap it in an array), see new line 519increment
is now only used for when an arg is given, use a default of1
instead of0
, see new line 674Through testing, I also found that previous functionality treated all arg values for a count flag equally (they all increment the count, regardless of value). This has been preserved, codified in a new test. We can consider changing this later if we want.
Hopefully this makes the logic a little more straightforward. 😎