Skip to content

Commit

Permalink
fix(App, Args): fixed subcommand reqs negation
Browse files Browse the repository at this point in the history
Closes #188
  • Loading branch information
Vinatorul authored and kbknapp committed Aug 24, 2015
1 parent 35114c9 commit b41afa8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

0 comments on commit b41afa8

Please sign in to comment.