Skip to content

Commit

Permalink
fix(assert): Make sure group members exist before using them
Browse files Browse the repository at this point in the history
In #3711, we had a confusing assert about no non-default members of a
required group when there were no defaults involved.  This is because
there were no valid args in the group but that check happens after.
  • Loading branch information
epage committed May 9, 2022
1 parent a57a411 commit 7c1f912
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/build/debug_asserts.rs
Expand Up @@ -301,6 +301,17 @@ pub(crate) fn assert_app(cmd: &Command) {
group.name,
);

for arg in &group.args {
// Args listed inside groups should exist
assert!(
cmd.get_arguments().any(|x| x.id == *arg),
"Command {}: Argument group '{}' contains non-existent argument '{:?}'",
cmd.get_name(),
group.name,
arg
);
}

// Required groups should have at least one arg without default values
if group.required && !group.args.is_empty() {
assert!(
Expand All @@ -313,17 +324,6 @@ pub(crate) fn assert_app(cmd: &Command) {
group.name
)
}

for arg in &group.args {
// Args listed inside groups should exist
assert!(
cmd.get_arguments().any(|x| x.id == *arg),
"Command {}: Argument group '{}' contains non-existent argument '{:?}'",
cmd.get_name(),
group.name,
arg
);
}
}

// Conflicts between flags and subcommands
Expand Down

0 comments on commit 7c1f912

Please sign in to comment.