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
min_values
when using Parser not respected
#3259
Comments
use clap::Parser;
#[derive(Parser, Debug)]
struct Args {
#[clap(short, max_values = 2)]
test: Vec<String>,
}
fn main() {
let args = Args::parse();
println!("{:#?}", args);
}
|
Turns out to make it work correctly is having a use clap::Parser;
#[derive(Parser, Debug)]
struct Args {
#[clap(short, min_values = 2, required = true)]
test: Vec<String>,
}
fn main() {
let args = Args::parse();
println!("{:#?}", args);
}
|
Actually this might be of design; I can figure a reason why someone would need to not require an arg's |
Currently, we only do min/max value checks against present arguments. I think keeping it that way makes sense but a caveat should be added to the documentation.
|
`min_values` is not respected without `required = True`, see also github.com/clap-rs/clap/issues/3259
@epage What about making |
Any changes along those lines would be a breaking change which won't happen until 4.0 at least but I am hoping to change a lot about how validation works in 4.0 between #2688 and #3476. I expect the only value count function that will exist will be for the number of values per occurrence and everything else will be handled through plugins, whether included with clap or written by end users. My hope is we'll be at a point where those plugins can opt arguments into being required or not, so that type of implication can be done. |
Please complete the following tasks
Rust Version
rustc 1.57.0 (f1edd0429 2021-11-29)
Clap Version
3.0.4
Minimal reproducible code
Steps to reproduce the bug with the above code
No arguments
Actual Behaviour
App executes, no error.
Expected Behaviour
An error should occur since there are not enough values for
--test
Additional Context
No response
Debug Output
The text was updated successfully, but these errors were encountered: