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

fix(assert): Detect conflicting arguments (unstable) #3701

Merged
merged 2 commits into from May 6, 2022
Merged
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
42 changes: 42 additions & 0 deletions src/build/debug_asserts.rs
Expand Up @@ -155,6 +155,14 @@ pub(crate) fn assert_app(cmd: &Command) {
}

for req in &arg.r_ifs {
#[cfg(feature = "unstable-v4")]
{
assert!(
!arg.is_required_set(),
"Argument {}: `required` conflicts with `required_if_eq*`",
arg.name
);
}
assert!(
cmd.id_exists(&req.0),
"Command {}: Argument or group '{:?}' specified in 'required_if_eq*' for '{}' does not exist",
Expand All @@ -165,6 +173,14 @@ pub(crate) fn assert_app(cmd: &Command) {
}

for req in &arg.r_ifs_all {
#[cfg(feature = "unstable-v4")]
{
assert!(
!arg.is_required_set(),
"Argument {}: `required` conflicts with `required_if_eq_all`",
arg.name
);
}
assert!(
cmd.id_exists(&req.0),
"Command {}: Argument or group '{:?}' specified in 'required_if_eq_all' for '{}' does not exist",
Expand All @@ -175,6 +191,32 @@ pub(crate) fn assert_app(cmd: &Command) {
}

for req in &arg.r_unless {
#[cfg(feature = "unstable-v4")]
{
assert!(
!arg.is_required_set(),
"Argument {}: `required` conflicts with `required_unless*`",
arg.name
);
}
assert!(
cmd.id_exists(req),
"Command {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist",
cmd.get_name(),
req,
arg.name,
);
}

for req in &arg.r_unless_all {
#[cfg(feature = "unstable-v4")]
{
assert!(
!arg.is_required_set(),
"Argument {}: `required` conflicts with `required_unless*`",
arg.name
);
}
assert!(
cmd.id_exists(req),
"Command {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist",
Expand Down