From 813060ea82d5b090e5b9effb31910f032ec8469d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 13 Oct 2022 13:03:14 -0500 Subject: [PATCH] refactor(error): Move bad-escape suggestion to general suggestion --- src/error/format.rs | 11 ----------- src/error/mod.rs | 12 +++++++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/error/format.rs b/src/error/format.rs index b39e5650d1f..58526dd46ef 100644 --- a/src/error/format.rs +++ b/src/error/format.rs @@ -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); diff --git a/src/error/mod.rs b/src/error/mod.rs index 91aa9e046b6..928261ac70f 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -690,9 +690,19 @@ impl Error { #[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