mirror of
https://github.com/clap-rs/clap
synced 2025-01-18 23:53:54 +00:00
Merge pull request #3205 from epage/unless
fix: Ensure we validate required-unless
This commit is contained in:
commit
ad127fcc53
2 changed files with 18 additions and 0 deletions
|
@ -37,6 +37,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
if let ParseState::Opt(a) = parse_state {
|
||||
debug!("Validator::validate: needs_val_of={:?}", a);
|
||||
self.validate_required(matcher)?;
|
||||
self.validate_required_unless(matcher)?;
|
||||
|
||||
let o = &self.p.app[&a];
|
||||
reqs_validated = true;
|
||||
|
|
|
@ -258,6 +258,23 @@ fn required_unless_err() {
|
|||
assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_unless_present_with_optional_value() {
|
||||
let res = App::new("unlesstest")
|
||||
.arg(Arg::new("opt").long("opt").min_values(0).max_values(1))
|
||||
.arg(
|
||||
Arg::new("cfg")
|
||||
.required_unless_present("dbg")
|
||||
.takes_value(true)
|
||||
.long("config"),
|
||||
)
|
||||
.arg(Arg::new("dbg").long("debug"))
|
||||
.try_get_matches_from(vec!["unlesstest", "--opt"]);
|
||||
|
||||
assert!(res.is_err());
|
||||
assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
}
|
||||
|
||||
// REQUIRED_UNLESS_ALL
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue