Skip to content

Commit

Permalink
fix(parser): Override required when parent group has conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 22, 2022
1 parent d145b8b commit 85ecb3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/parser/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,17 @@ impl<'cmd> Validator<'cmd> {

fn is_missing_required_ok(&self, a: &Arg, conflicts: &Conflicts) -> bool {
debug!("Validator::is_missing_required_ok: {}", a.get_id());
let conflicts = conflicts.gather_conflicts(self.cmd, a.get_id());
!conflicts.is_empty()
if !conflicts.gather_conflicts(self.cmd, a.get_id()).is_empty() {
debug!("Validator::is_missing_required_ok: true (self)");
return true;
}
for group_id in self.cmd.groups_for_arg(a.get_id()) {
if !conflicts.gather_conflicts(self.cmd, &group_id).is_empty() {
debug!("Validator::is_missing_required_ok: true ({})", group_id);
return true;
}
}
false
}

// Failing a required unless means, the arg's "unless" wasn't present, and neither were they
Expand Down
4 changes: 3 additions & 1 deletion tests/builder/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ fn arg_conflicts_with_group_with_required_memeber() {
}

let result = cmd.try_get_matches_from_mut(vec!["myprog", "--flag"]);
assert!(result.is_err());
if let Err(err) = result {
panic!("{}", err);
}
}

#[test]
Expand Down

0 comments on commit 85ecb3e

Please sign in to comment.