Repository navigation
Conversation
When an array option is configured with both a default and narg / requiresArg, providing the flag without a following value used to fill argsToSet from the default and skip the nargs length check. Non-array options already report "Not enough arguments following" in that case. Leave argsToSet empty when nargs requires a value so the existing check fires; defaults still apply when the flag is omitted entirely. Fixes yargs#445
Member
|
Unsolicited Pull Requests may be closed without discussion. For more see Contributing and AI Policy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #445.
When an option is
array+narg/requiresArg+default, passing the flag with no following value used to load the default intoargsToSetinsideeatArray, which made the nargs length check pass. Non-array options already error withNot enough arguments following: <key>in the same situation.Change
In
eatArray, skip filling fromdefaultswhennargrequires at least one value (numeric count> 0orNaN). The existing nargs check then reports the error. Defaults still apply when the flag is omitted entirely (applyDefaultsAndAliases), and a bare flag withoutnargstill gets the array default as before.Test plan
array with nargsfor#445(narg1andNaNwith default; bare flag omitted; bare flag without narg)npm test— 369 passing