Refactor the part of .addOption()
responsible for storing the default value
#1961
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.
Disclaimer: The change introduced here is of low importance.
The change has been manually cherry-picked from the now-closed #1915 so that it can be discussed independently.
Problem
When a default value is explicitly specified for the negating component of a negatable option (the one whose long flag is prefixed with
--no-
), it should be set as the default value for the option just like in case of the non-negating component (or a regular, non-negatable option).That is exactly what happens in the current
.addOption()
code except for one case, namely when the non-negating component had already been added earlier. To check if that is the case,._findOption()
has to be called, and that seems excessive.Demo
Solution
Eliminate excessive
._findOption()
calls andundefined
checks.The change can be considered breaking because
none
is logged when running the demo program from above after it is applied, so might want to include it in the next major release. However, code similar to the demo is so unlikely to have ever been written that I don't think caring about it is worth it.