mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 23:04:23 +00:00
parent
35114c99c5
commit
b41afa8c3d
2 changed files with 14 additions and 2 deletions
|
@ -2391,7 +2391,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
|
||||||
self.print_help();
|
self.print_help();
|
||||||
self.exit(1);
|
self.exit(1);
|
||||||
}
|
}
|
||||||
if (!self.subcmds_neg_reqs) && self.validate_required(&matches) {
|
if ((!self.subcmds_neg_reqs) || matches.subcommand_name().is_none()) && self.validate_required(&matches) {
|
||||||
self.report_error(format!("The following required arguments were not \
|
self.report_error(format!("The following required arguments were not \
|
||||||
supplied:{}",
|
supplied:{}",
|
||||||
self.get_required_from(self.required.iter()
|
self.get_required_from(self.required.iter()
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -27,7 +27,7 @@ mod fmt;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{App, Arg, SubCommand};
|
use super::{App, Arg, SubCommand, AppSettings};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
|
||||||
|
@ -1255,4 +1255,16 @@ mod tests {
|
||||||
App::new("short_flag")
|
App::new("short_flag")
|
||||||
.arg(Arg::from_usage("-f 'some flag'"));
|
.arg(Arg::from_usage("-f 'some flag'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sub_command_negate_requred() {
|
||||||
|
App::new("sub_command_negate")
|
||||||
|
.setting(AppSettings::SubcommandsNegateReqs)
|
||||||
|
.arg(Arg::with_name("test")
|
||||||
|
.required(true)
|
||||||
|
.index(1))
|
||||||
|
.subcommand(SubCommand::with_name("sub1"))
|
||||||
|
.subcommand(SubCommand::with_name("sub1"))
|
||||||
|
.get_matches_from(vec!["", "sub1"]);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue