Skip to content
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

max_values confusingly returns ErrorKind::UnknownArgument when too many arguments are provided #3760

Open
2 tasks done
SilvanCodes opened this issue May 26, 2022 · 1 comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@SilvanCodes
Copy link

Please complete the following tasks

Clap Version

3.1.15

Describe your use case

I want to limit the maximum given arguments with a proper error message for the user when too many arguments are provided.

Describe the solution you'd like

Instead of ErrorKind::UnknownArgument I would like max_values to return a new error kind like ErrorKind::TooManyValues mirroring the behavior of min_values with its error kind ErrorKind::TooFewValues.

Alternatives, if applicable

No response

Additional Context

No response

@SilvanCodes SilvanCodes added the C-enhancement Category: Raise on the bar on expectations label May 26, 2022
@epage
Copy link
Member

epage commented May 26, 2022

With TooFewValues, there is a definitive case for us to identify and report an error: the parser was looking for more values and didn't see them.

TooManyValues is a bit trickier because the parser exhausted one argument and is processing the next, finding it doesn't exist. We'd need to match against a trailing argument that took a value but there are no more positional or subcommands afterwards. The error also might not make sense for an argument that just takes one value. Or maybe it does.

Then it comes to the implementation. Our parser isn't in a great state right now though hopefully some in going refactors will improve things a bit.

This isn't a "no" but that parts of the design need to be figured out and that we might wait for some refactorings before its practical to implement.

@epage epage added A-parsing Area: Parser's logic and needs it changed somehow. S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing labels May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

2 participants