Skip to content

Commit

Permalink
fix(assert): Detect conflicting arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 6, 2022
1 parent 3d7ee2e commit 6354f2a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/build/debug_asserts.rs
Expand Up @@ -155,6 +155,13 @@ 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*`"
);
}
assert!(
cmd.id_exists(&req.0),
"Command {}: Argument or group '{:?}' specified in 'required_if_eq*' for '{}' does not exist",
Expand All @@ -165,6 +172,13 @@ 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`"
);
}
assert!(
cmd.id_exists(&req.0),
"Command {}: Argument or group '{:?}' specified in 'required_if_eq_all' for '{}' does not exist",
Expand All @@ -175,6 +189,13 @@ 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*`"
);
}
assert!(
cmd.id_exists(req),
"Command {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist",
Expand All @@ -185,6 +206,13 @@ pub(crate) fn assert_app(cmd: &Command) {
}

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

0 comments on commit 6354f2a

Please sign in to comment.