fix: strict should fail unknown arguments#1977
Merged
bcoe merged 3 commits intoyargs:masterfrom Jul 11, 2021
jly36963:fix-strict-false-negative-bug
Merged
fix: strict should fail unknown arguments#1977bcoe merged 3 commits intoyargs:masterfrom jly36963:fix-strict-false-negative-bug
bcoe merged 3 commits intoyargs:masterfrom
jly36963:fix-strict-false-negative-bug
Conversation
Member
|
@jly36963 thanks for digging into this, will make an effort to review this week 👍 It's great to start squashing some of the long standing bugs. |
bcoe
approved these changes
Jul 10, 2021
Member
|
@biggianteye, @brlodi, I've published @jly36963's fix to
|
I've just tested this version with the code I used in the bug report and it is now working as expected. Thanks! |
kevinoid
added a commit
to kevinoid/hub-ci-status
that referenced
this pull request
Aug 5, 2021
The problems which previously motivated me to switch from commander to
yargs have been solved (by the addition of .exitOverride() and
.configureOutput()). Commander has more flexibility than yargs for
option processing using .on('option'), which can be used for options
which are sensitive to ordering or have more complicated handling. It
is also much simpler and has less exotic behavior that needs to be
disabled (see all the yargs options which were set). Finally, it is
about 1/6 the total size.
Also, for this project specifically, [email protected] broke positional
argument parsing due to yargs/yargs#1977. Since the argument is
optional, `.demand()` is not appropriate (it's also deprecated). It
appears the correct fix would be to add a default command and define the
positional argument on that. However, I'm done dealing with yargs
breakage, and switching to Commander will a better return on effort.
Signed-off-by: Kevin Locke <[email protected]>
This was referenced Nov 25, 2021
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.
Addresses: #1861
As always, let me know if I need to change/add/fix anything.
Issue
This should fail:
Neither
unknownArgumentsnorunknownCommandscatch extra args whencommandKeys.lengthis 0.Fix
I added a block to check if there are any elements in
argvthat aren't incurrentContext.commands. I made sure to tolerate args whenyargs.demand(number)is called, when the number of args falls within the min/max range.This shouldn't fail:
Note
I don't understand the
demandlogic well (as it's deprecated and not in the docs), so I'm not sure if the slice in this line will always be correct:I saw that a few other places do something similar.