From 7417c75c57b8a7f0fd9563237c2b829021b52d5f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 13 Oct 2022 12:59:13 -0500 Subject: [PATCH] refactor(error): Move escaped-subcmd suggestion to general suggestions --- src/error/format.rs | 9 --------- src/error/mod.rs | 13 ++++++++++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/error/format.rs b/src/error/format.rs index a95bebddb12..b39e5650d1f 100644 --- a/src/error/format.rs +++ b/src/error/format.rs @@ -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 { diff --git a/src/error/mod.rs b/src/error/mod.rs index 6d8502f56f6..91aa9e046b6 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -426,11 +426,18 @@ impl Error { name: String, usage: Option, ) -> 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)), ( @@ -438,8 +445,8 @@ impl Error { ContextValue::Strings(did_you_mean), ), ( - ContextKind::SuggestedCommand, - ContextValue::String(suggestion), + ContextKind::Suggested, + ContextValue::StyledStrs(vec![styled_suggestion]), ), ]); if let Some(usage) = usage {