Skip to content

Commit

Permalink
fix(error): Specialize the self-conflicts error
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 29, 2022
1 parent 2c09781 commit 4e9f3cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/tutorial_builder/03_01_flag_bool.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ verbose: true

$ 03_01_flag_bool --verbose --verbose
? failed
error: The argument '--verbose' cannot be used with '--verbose'
error: The argument '--verbose' was provided more than once, but cannot be used multiple times

Usage: 03_01_flag_bool[EXE] [OPTIONS]

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_derive/03_01_flag_bool.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ verbose: true

$ 03_01_flag_bool_derive --verbose --verbose
? failed
error: The argument '--verbose' cannot be used with '--verbose'
error: The argument '--verbose' was provided more than once, but cannot be used multiple times

Usage: 03_01_flag_bool_derive[EXE] [OPTIONS]

Expand Down
42 changes: 24 additions & 18 deletions src/error/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,32 @@ fn write_dynamic_context(error: &crate::error::Error, styled: &mut StyledStr) ->
if let (Some(ContextValue::String(invalid_arg)), Some(prior_arg)) =
(invalid_arg, prior_arg)
{
styled.none("The argument '");
styled.warning(invalid_arg);
styled.none("' cannot be used with");
if ContextValue::String(invalid_arg.clone()) == *prior_arg {
styled.none("The argument '");
styled.warning(invalid_arg);
styled.none("' was provided more than once, but cannot be used multiple times");
} else {
styled.none("The argument '");
styled.warning(invalid_arg);
styled.none("' cannot be used with");

match prior_arg {
ContextValue::Strings(values) => {
styled.none(":");
for v in values {
styled.none("\n");
styled.none(TAB);
styled.warning(&**v);
match prior_arg {
ContextValue::Strings(values) => {
styled.none(":");
for v in values {
styled.none("\n");
styled.none(TAB);
styled.warning(&**v);
}
}
ContextValue::String(value) => {
styled.none(" '");
styled.warning(value);
styled.none("'");
}
_ => {
styled.none(" one or more of the other specified arguments");
}
}
ContextValue::String(value) => {
styled.none(" '");
styled.warning(value);
styled.none("'");
}
_ => {
styled.none(" one or more of the other specified arguments");
}
}
true
Expand Down
2 changes: 1 addition & 1 deletion tests/builder/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ For more information try '--help'
#[cfg(feature = "error-context")]
fn conflict_output_repeat() {
static ERR: &str = "\
error: The argument '-F' cannot be used with '-F'
error: The argument '-F' was provided more than once, but cannot be used multiple times
Usage: clap-test [OPTIONS] [positional] [positional2] [positional3]... [COMMAND]
Expand Down

0 comments on commit 4e9f3cc

Please sign in to comment.