Skip to content

Commit

Permalink
fix(parser): Allow exclusive to override required_*
Browse files Browse the repository at this point in the history
There are other cases for `required` that aren't being handled
- Groups
- Conflicts

I'm concerned there might be weird corner cases and didn't want the
analysis for that to block fixing this.

Fixes #5507
  • Loading branch information
epage committed Jun 6, 2024
1 parent f70c6d6 commit d3633a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clap_builder/src/parser/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<'cmd> Validator<'cmd> {
required = true;
}

if required {
if !is_exclusive_present && required {
missing_required.push(a.get_id().clone());
if !a.is_last_set() {
highest_index = highest_index.max(a.get_index().unwrap_or(0));
Expand Down
6 changes: 3 additions & 3 deletions tests/builder/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ fn exclusive_with_required_unless_present() {

cmd.clone()
.try_get_matches_from(["bug", "--exclusive"])
.unwrap_err();
.unwrap();
}

#[test]
Expand Down Expand Up @@ -761,7 +761,7 @@ fn exclusive_with_required_unless_present_any() {

cmd.clone()
.try_get_matches_from(["bug", "--exclusive"])
.unwrap_err();
.unwrap();
}

#[test]
Expand Down Expand Up @@ -801,7 +801,7 @@ fn exclusive_with_required_unless_present_all() {

cmd.clone()
.try_get_matches_from(["bug", "--exclusive"])
.unwrap_err();
.unwrap();
}

#[test]
Expand Down

0 comments on commit d3633a8

Please sign in to comment.