Skip to content

Commit

Permalink
fix(parser): Allow one-off self-overrides
Browse files Browse the repository at this point in the history
bat needed this.

See also clap-rs#4261
  • Loading branch information
epage committed Sep 28, 2022
1 parent 2d78749 commit 82d8de4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 0 additions & 5 deletions src/builder/debug_asserts.rs
Expand Up @@ -686,11 +686,6 @@ fn assert_arg(arg: &Arg) {
"Argument '{}' cannot conflict with itself",
arg.get_id(),
);
assert!(
!arg.overrides.iter().any(|x| *x == arg.id),
"Argument '{}' cannot override itself, its the default",
arg.get_id(),
);

assert_eq!(
arg.get_action().takes_values(),
Expand Down
12 changes: 9 additions & 3 deletions src/parser/parser.rs
Expand Up @@ -1180,7 +1180,9 @@ impl<'cmd> Parser<'cmd> {
self.cur_idx.set(self.cur_idx.get() + 1);
debug!("Parser::react: cur_idx:={}", self.cur_idx.get());
}
if matcher.remove(&arg.id) && !self.cmd.is_args_override_self() {
if matcher.remove(&arg.id)
&& !(self.cmd.is_args_override_self() || arg.overrides.contains(arg.get_id()))
{
return Err(ClapError::argument_conflict(
self.cmd,
arg.to_string(),
Expand Down Expand Up @@ -1221,7 +1223,9 @@ impl<'cmd> Parser<'cmd> {
raw_vals
};

if matcher.remove(&arg.id) && !self.cmd.is_args_override_self() {
if matcher.remove(&arg.id)
&& !(self.cmd.is_args_override_self() || arg.overrides.contains(arg.get_id()))
{
return Err(ClapError::argument_conflict(
self.cmd,
arg.to_string(),
Expand All @@ -1240,7 +1244,9 @@ impl<'cmd> Parser<'cmd> {
raw_vals
};

if matcher.remove(&arg.id) && !self.cmd.is_args_override_self() {
if matcher.remove(&arg.id)
&& !(self.cmd.is_args_override_self() || arg.overrides.contains(arg.get_id()))
{
return Err(ClapError::argument_conflict(
self.cmd,
arg.to_string(),
Expand Down

0 comments on commit 82d8de4

Please sign in to comment.