From 08656d046ebfe866c4c2cd5757d546c7fbd7ce7f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 6 Jun 2024 15:01:04 -0500 Subject: [PATCH] fix(parser): Allow `exclusive` to override required_* 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 --- clap_builder/src/parser/validator.rs | 2 +- tests/builder/conflicts.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clap_builder/src/parser/validator.rs b/clap_builder/src/parser/validator.rs index f2f2164c4bf..d62fd8109ed 100644 --- a/clap_builder/src/parser/validator.rs +++ b/clap_builder/src/parser/validator.rs @@ -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)); diff --git a/tests/builder/conflicts.rs b/tests/builder/conflicts.rs index 65eee61de38..bd9c42ede8d 100644 --- a/tests/builder/conflicts.rs +++ b/tests/builder/conflicts.rs @@ -721,7 +721,7 @@ fn exclusive_with_required_unless_present() { cmd.clone() .try_get_matches_from(["bug", "--exclusive"]) - .unwrap_err(); + .unwrap(); } #[test] @@ -761,7 +761,7 @@ fn exclusive_with_required_unless_present_any() { cmd.clone() .try_get_matches_from(["bug", "--exclusive"]) - .unwrap_err(); + .unwrap(); } #[test] @@ -801,7 +801,7 @@ fn exclusive_with_required_unless_present_all() { cmd.clone() .try_get_matches_from(["bug", "--exclusive"]) - .unwrap_err(); + .unwrap(); } #[test]