Skip to content

Commit

Permalink
refactor(error): Give caller control over suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Aug 16, 2023
1 parent 8413c15 commit 13e3770
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clap_builder/src/error/mod.rs
Expand Up @@ -718,7 +718,7 @@ impl<F: ErrorFormatter> Error<F> {
let mut styled_suggestion = StyledStr::new();
let _ = write!(
styled_suggestion,
"'{}{sub} --{flag}{}' exists",
"'{}{sub} {flag}{}' exists",
valid.render(),
valid.render_reset()
);
Expand All @@ -727,7 +727,7 @@ impl<F: ErrorFormatter> Error<F> {
Some((flag, None)) => {
err = err.insert_context_unchecked(
ContextKind::SuggestedArg,
ContextValue::String(format!("--{flag}")),
ContextValue::String(flag),
);
}
None => {}
Expand Down
1 change: 1 addition & 0 deletions clap_builder/src/parser/parser.rs
Expand Up @@ -1521,6 +1521,7 @@ impl<'cmd> Parser<'cmd> {
self.start_custom_arg(matcher, arg, ValueSource::CommandLine);
}
}
let did_you_mean = did_you_mean.map(|(arg, cmd)| (format!("--{arg}"), cmd));

let required = self.cmd.required_graph();
let used: Vec<Id> = matcher
Expand Down
4 changes: 2 additions & 2 deletions tests/builder/error.rs
Expand Up @@ -229,7 +229,7 @@ fn unknown_argument_option() {
static MESSAGE: &str = "\
error: unexpected argument '--cwd <current-dir-unknown>' found
tip: a similar argument exists: '---C'
tip: a similar argument exists: '-C'
Usage: test [OPTIONS]
Expand Down Expand Up @@ -259,7 +259,7 @@ fn unknown_argument_flag() {
static MESSAGE: &str = "\
error: unexpected argument '--ignored' found
tip: a similar argument exists: '---- --ignored'
tip: a similar argument exists: '-- --ignored'
Usage: test [OPTIONS]
Expand Down

0 comments on commit 13e3770

Please sign in to comment.