Merge pull request #3712 from epage/assert

fix(assert): Make sure group members exist before using them
This commit is contained in:
Ed Page 2022-05-10 14:40:26 -05:00 committed by GitHub
commit 9713cd9ae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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!(
@ -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