Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include groups in get_arg_conflicts_with #3902

Merged
merged 1 commit into from Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/builder/command.rs
Expand Up @@ -3556,15 +3556,21 @@ impl<'help> App<'help> {
if arg.is_global_set() {
self.get_global_arg_conflicts_with(arg)
} else {
arg.blacklist
.iter()
.map(|id| {
self.args.args().find(|arg| arg.id == *id).expect(
"Command::get_arg_conflicts_with: \
The passed arg conflicts with an arg unknown to the cmd",
)
})
.collect()
let mut result = Vec::new();
for id in arg.blacklist.iter() {
if let Some(arg) = self.find(id) {
result.push(arg);
} else if let Some(group) = self.find_group(id) {
result.extend(
self.unroll_args_in_group(&group.id)
.iter()
.map(|id| self.find(id).expect(INTERNAL_ERROR_MSG)),
);
} else {
panic!("Command::get_arg_conflicts_with: The passed arg conflicts with an arg unknown to the cmd");
}
}
result
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/builder/conflicts.rs
Expand Up @@ -296,6 +296,24 @@ fn required_group_conflicts_with_arg() {
}
}

#[test]
epage marked this conversation as resolved.
Show resolved Hide resolved
fn get_arg_conflicts_with_group() {
let flag = arg!(--flag).conflicts_with("gr");
let mut cmd = Command::new("group_conflict")
.arg(&flag)
.group(ArgGroup::new("gr").arg("some").arg("other"))
.arg(arg!(--some))
.arg(arg!(--other));

cmd.build();

let result = cmd.get_arg_conflicts_with(&flag);

assert_eq!(result.len(), 2);
assert_eq!(result[0].get_id(), "some");
assert_eq!(result[1].get_id(), "other");
}

#[test]
fn conflict_output() {
utils::assert_output(
Expand Down