-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: support MatchValid(PositionalArgs) OR MinimumValidNArgs, MaximumValidNArgs, RangeValidArgs #838
Comments
This issue is being marked as stale due to a long period of inactivity |
This is still an issue. It will be closed when #841 (or some other solution) is merged. |
Took the stale label away since the PR referenced that would fix this is still active. |
The alternative solution proposed in the description of this issue is now available thanks to #896 and the new Lines 111 to 112 in 03c3eb7
I'm going to go ahead and close this as fixed. |
IMHO, this issue should be kept open until either:
Using See #745 (comment). |
For consistency, I think it would be useful to have
MinimumValidNArgs(int)
,MaximumValidNArgs(int)
andRangeValidArgs(min, max)
added to the list of supportedArgs
formats. The complete list would then be:This is because AFAIK it is not possible ATM to combine e.g.
MinimumNArgs(1)
withOnlyValidArgs
.An alternative solution is to provide a built-in function such as
matchAll
by @Antolius in #745. For example:which would allow the following expressions:
Args: cobra.MatchValid(cobra.MinimumNArgs(1)), ValidArgs: []string{...}
Args: cobra.MatchValid(cobra.MaximumNArgs(5)), ValidArgs: []string{...}
Args: cobra.MatchValid(cobra.RangeArgs(1, 5)), ValidArgs: []string{...}
Args: cobra.MatchValid(cobra.ArbitraryArgs), ValidArgs: []string{...}
Args: cobra.MatchValid(cobra.ExactArgs(1)), ValidArgs: []string{...}
Certainly,
MatchValid
can be used implicitly whenValidArgs
is defined, so the user is not required to type it. Therefore,OnlyValidArgs
andExactValidArgs
can be deprecated from the public API. The list of formats would be:The text was updated successfully, but these errors were encountered: