Merge pull request #3974 from epage/conflict

fix!: Ignore required when subcommands conflict with required
This commit is contained in:
Ed Page 2022-07-22 14:25:12 -05:00 committed by GitHub
commit ce8ebe1ccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -3845,6 +3845,10 @@ impl<'help> Command<'help> {
self.settings.insert(AppSettings::DisableHelpFlag.into());
self.settings.insert(AppSettings::DisableVersionFlag.into());
}
if self.is_set(AppSettings::ArgsNegateSubcommands) {
self.settings
.insert(AppSettings::SubcommandsNegateReqs.into());
}
self._propagate();
self._check_help_and_version();

View file

@ -609,3 +609,20 @@ fn exclusive_with_required() {
cmd.clone().try_get_matches_from(["bug", "--test"]).unwrap();
}
#[test]
fn subcommand_conflict_negates_required() {
let cmd = Command::new("test")
.args_conflicts_with_subcommands(true)
.subcommand(Command::new("config"))
.arg(arg!(-p --place <"place id"> "Place ID to open"));
let result = cmd.try_get_matches_from(["test", "config"]);
assert!(
result.is_ok(),
"args_conflicts_with_subcommands should ignore required: {}",
result.unwrap_err()
);
let m = result.unwrap();
assert_eq!(m.subcommand_name().unwrap(), "config");
}