feat: interpret demand() numbers as relative to executing command#582
Merged
Conversation
This was referenced Aug 14, 2016
Closed
Contributor
|
Just got bit by this not being marked as a breaking change in the v5 changelog, must have slipped through the cracks! 😆 |
Member
Author
|
@mathieumg Whoops, you're right, looks like we forgot to use the |
Member
|
@nexdrew @mathieumg mind updating the CHANGELOG for v5 post-hoc, save others :) |
mathieumg
added a commit
to mathieumg/yargs
that referenced
this pull request
Oct 18, 2016
Contributor
|
@bcoe Done! |
nexdrew
pushed a commit
that referenced
this pull request
Oct 18, 2016
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.
Fixes #451.
Previously, min and max values passed to
.demand()were interpreted as the total number of non-option arguments, which included the arguments representing the command(s) itself.With this PR, the min and max values are now interpreted as the additional number of non-option arguments, relative to the currently executing command.
Here's an example:
Before this PR, the command would not work as expected (i.e. would not accept any flagless args) because the
lintcommand itself would satisfy the min and max on the command line.After this PR, the command works by requiring a single flagless arg on the command line besides the
lintcommand itself.When
.demand()is used outside of a command builder, the functionality remains the same.Note that this is a BREAKING CHANGE since users relying on the previous (now deemed incorrect) functionality will need to change the values they pass to
.demand()within command builders, decrementing them by the "nested/depth count" of the command.Also note that this does not change the contents of
argv._within the command handler;argv._still contains the command key(s) it took to execute the command(s). (Note the use ofargv._[1]in the above example.)We could possibly change this (which would be another breaking change), but I'd rather leave it this way to potentially support command handlers that are reusable across multiple commands (allowing the handler to slightly change its functionality based on the command keys present in
argv._).