Skip to content

Commit

Permalink
refactor(error): Move bad-escape suggestion to general suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 13, 2022
1 parent 7417c75 commit 813060e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 0 additions & 11 deletions src/error/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ impl ErrorFormatter for RichFormatter {
styled.good(invalid_arg);
styled.none("'");
}

let trailing_arg = error.get(ContextKind::TrailingArg);
if trailing_arg == Some(&ContextValue::Bool(true)) {
styled.none("\n\n");
styled.none(TAB);
styled.none("If you tried to supply '");
styled.warning(invalid_arg);
styled.none("' as a subcommand, remove the '");
styled.warning("--");
styled.none("' before it.");
}
}

let suggestions = error.get(ContextKind::Suggested);
Expand Down
12 changes: 11 additions & 1 deletion src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,19 @@ impl<F: ErrorFormatter> Error<F> {

#[cfg(feature = "error-context")]
{
let mut styled_suggestion = StyledStr::new();
styled_suggestion.none("If you tried to supply '");
styled_suggestion.warning(&arg);
styled_suggestion.none("' as a subcommand, remove the '");
styled_suggestion.warning("--");
styled_suggestion.none("' before it.");

err = err.extend_context_unchecked([
(ContextKind::InvalidArg, ContextValue::String(arg)),
(ContextKind::TrailingArg, ContextValue::Bool(true)),
(
ContextKind::Suggested,
ContextValue::StyledStrs(vec![styled_suggestion]),
),
]);
if let Some(usage) = usage {
err = err
Expand Down

0 comments on commit 813060e

Please sign in to comment.