Skip to content

Commit

Permalink
fix(assert): prevent arguments from requiring self
Browse files Browse the repository at this point in the history
It's non-sensical for an argument to require itself, so it must be a
mistake, and should be prevented.

This is arguably a breaking change, but of the spacebar heating kind.

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
  • Loading branch information
omertuc committed Dec 3, 2024
1 parent b4ea2d4 commit a3a1735
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions clap_builder/src/builder/debug_asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,18 @@ pub(crate) fn assert_app(cmd: &Command) {
}

// requires, r_if, r_unless
for req in &arg.requires {
for (_predicate, req_id) in &arg.requires {
assert!(
cmd.id_exists(&req.1),
&arg.id != req_id,
"Argument {} cannot require itself",
arg.get_id()
);

assert!(
cmd.id_exists(req_id),
"Command {}: Argument or group '{}' specified in 'requires*' for '{}' does not exist",
cmd.get_name(),
req.1,
req_id,
arg.get_id(),
);
}
Expand Down

0 comments on commit a3a1735

Please sign in to comment.