Skip to content

Commit

Permalink
Merge pull request #4867 from epage/panic
Browse files Browse the repository at this point in the history
fix(builder): Assert earlier on bad requires/conflicts
  • Loading branch information
epage authored Apr 27, 2023
2 parents 6b23edc + 185729a commit 9eaf899
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions clap_builder/src/builder/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ pub(crate) fn assert_app(cmd: &Command) {
arg
);
}

for arg in &group.requires {
// Args listed inside groups should exist
assert!(
cmd.id_exists(arg),
"Command {}: Argument group '{}' requires non-existent '{}' id",
cmd.get_name(),
group.get_id(),
arg
);
}

for arg in &group.conflicts {
// Args listed inside groups should exist
assert!(
cmd.id_exists(arg),
"Command {}: Argument group '{}' conflicts with non-existent '{}' id",
cmd.get_name(),
group.get_id(),
arg
);
}
}

// Conflicts between flags and subcommands
Expand Down
2 changes: 1 addition & 1 deletion clap_builder/src/output/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl<'cmd> Usage<'cmd> {
required_groups.insert(elem);
required_groups_members.extend(group_members);
} else {
debug_assert!(self.cmd.find(req).is_some());
debug_assert!(self.cmd.find(req).is_some(), "`{req}` must exist");
}
}

Expand Down

0 comments on commit 9eaf899

Please sign in to comment.