fix(App, Args): fixed subcommand reqs negation

Closes #188
This commit is contained in:
Alexander Kuvaev 2015-08-24 20:21:51 +03:00 committed by Kevin K
parent 35114c99c5
commit b41afa8c3d
2 changed files with 14 additions and 2 deletions

View file

@ -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()

View file

@ -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"]);
}
} }