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

Validate all arguments together #2332

Closed
2 tasks done
giggio opened this issue Feb 6, 2021 · 2 comments
Closed
2 tasks done

Validate all arguments together #2332

giggio opened this issue Feb 6, 2021 · 2 comments
Labels
A-parsing Area: Parser's logic and needs it changed somehow. A-validators Area: ArgMatches validation logi C-enhancement Category: Raise on the bar on expectations S-duplicate Status: Closed as Duplicate

Comments

@giggio
Copy link

giggio commented Feb 6, 2021

Make sure you completed the following tasks

Describe your use case

I'd like to have a validation function that would validate the arguments together.

Describe the solution you'd like

I'm thinking something like this:

App::new("x")
    .validate(|args| /* some logic and... */ Err(("myarg", "Why invalid"));

(I'm not married to this example, it is just so we can have an idea)

In this case, argument myarg is invalid, after I've gone through some logic that would go through all arguments already supplied (and validated individually).

Alternatives, if applicable

Validate after parsing using ArgMatches.

Additional context

Already discussed at #1913 and #1206, and I think a solution with a closure after on the app context could make sense.

@pksunkara pksunkara added A-validators Area: ArgMatches validation logi A-parsing Area: Parser's logic and needs it changed somehow. labels Feb 6, 2021
@epage epage added C-enhancement Category: Raise on the bar on expectations and removed T: new feature labels Dec 8, 2021
@epage
Copy link
Member

epage commented Dec 13, 2021

Note that in clap3 we added App::error for being able to create custom validation with ArgMatches that looks as if it was from a validator.

#3008 is our other generalization of validation.

Closing this in favor of App::error and #3008. If there is any concern with this, feel free to let us know!

@epage epage closed this as completed Dec 13, 2021
@ctrlcctrlv
Copy link

MFEK's fork can do this and was rejected in #3029. If you need a solution right now like we did you could use it. We are waiting for a resolution to #3008 to be able to drop our fork and track upstream again.

@epage epage added the S-duplicate Status: Closed as Duplicate label Jan 11, 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. A-validators Area: ArgMatches validation logi C-enhancement Category: Raise on the bar on expectations S-duplicate Status: Closed as Duplicate
Projects
None yet
Development

No branches or pull requests

4 participants