mirror of
https://github.com/clap-rs/clap
synced 2024-12-12 13:52:34 +00:00
Merge pull request #3974 from epage/conflict
fix!: Ignore required when subcommands conflict with required
This commit is contained in:
commit
ce8ebe1ccc
2 changed files with 21 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue