Skip to content

Commit

Permalink
refactor(error): Move escaped-subcmd suggestion to general suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 13, 2022
1 parent c8cb5bb commit 7417c75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
9 changes: 0 additions & 9 deletions src/error/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@ impl ErrorFormatter for RichFormatter {
}
}

let suggestion = error.get(ContextKind::SuggestedCommand);
if let Some(ContextValue::String(suggestion)) = suggestion {
styled.none("\n\n");
styled.none(TAB);
styled.none("If you believe you received this message in error, try re-running with '");
styled.good(suggestion);
styled.none("'");
}

let suggestions = error.get(ContextKind::Suggested);
if let Some(ContextValue::StyledStrs(suggestions)) = suggestions {
for suggestion in suggestions {
Expand Down
13 changes: 10 additions & 3 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,20 +426,27 @@ impl<F: ErrorFormatter> Error<F> {
name: String,
usage: Option<StyledStr>,
) -> Self {
let suggestion = format!("{} -- {}", name, subcmd);
let mut err = Self::new(ErrorKind::InvalidSubcommand).with_cmd(cmd);

#[cfg(feature = "error-context")]
{
let mut styled_suggestion = StyledStr::new();
styled_suggestion
.none("If you believe you received this message in error, try re-running with '");
styled_suggestion.good(name);
styled_suggestion.good(" -- ");
styled_suggestion.good(&subcmd);
styled_suggestion.none("'");

err = err.extend_context_unchecked([
(ContextKind::InvalidSubcommand, ContextValue::String(subcmd)),
(
ContextKind::SuggestedSubcommand,
ContextValue::Strings(did_you_mean),
),
(
ContextKind::SuggestedCommand,
ContextValue::String(suggestion),
ContextKind::Suggested,
ContextValue::StyledStrs(vec![styled_suggestion]),
),
]);
if let Some(usage) = usage {
Expand Down

0 comments on commit 7417c75

Please sign in to comment.