diff --git a/src/app.rs b/src/app.rs index 6a299518103..953ce51aa17 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2391,7 +2391,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ self.print_help(); 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 \ supplied:{}", self.get_required_from(self.required.iter() diff --git a/src/lib.rs b/src/lib.rs index 1f846d00836..9f34d5dc344 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ mod fmt; #[cfg(test)] mod tests { - use super::{App, Arg, SubCommand}; + use super::{App, Arg, SubCommand, AppSettings}; use std::collections::HashSet; use std::vec::Vec; @@ -1255,4 +1255,16 @@ mod tests { App::new("short_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"]); + } } \ No newline at end of file