diff --git a/src/error/format.rs b/src/error/format.rs index 5e78e08fdaf..2e0f8e9f824 100644 --- a/src/error/format.rs +++ b/src/error/format.rs @@ -64,30 +64,18 @@ impl ErrorFormatter for RichFormatter { } } - if let Some(valid) = error.get(ContextKind::SuggestedValue) { + if let Some(valid) = error.get(ContextKind::SuggestedSubcommand) { styled.none("\n\n"); did_you_mean(&mut styled, valid); } - - let valid_sub = error.get(ContextKind::SuggestedSubcommand); - let valid_arg = error.get(ContextKind::SuggestedArg); - match (valid_sub, valid_arg) { - (Some(ContextValue::String(valid_sub)), Some(ContextValue::String(valid_arg))) => { - styled.none("\n\n"); - styled.none(TAB); - styled.none("Did you mean to put '"); - styled.good(valid_arg); - styled.none("' after the subcommand '"); - styled.good(valid_sub); - styled.none("'?"); - } - (Some(valid), None) | (None, Some(valid)) => { - styled.none("\n\n"); - did_you_mean(&mut styled, valid); - } - (_, _) => {} + if let Some(valid) = error.get(ContextKind::SuggestedArg) { + styled.none("\n\n"); + did_you_mean(&mut styled, valid); + } + if let Some(valid) = error.get(ContextKind::SuggestedValue) { + styled.none("\n\n"); + did_you_mean(&mut styled, valid); } - 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 4ec2d0cc3f0..af65529fce8 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -672,14 +672,14 @@ impl Error { } match did_you_mean { Some((flag, Some(sub))) => { - err = err.insert_context_unchecked( - ContextKind::SuggestedSubcommand, - ContextValue::String(sub), - ); - err = err.insert_context_unchecked( - ContextKind::SuggestedArg, - ContextValue::String(format!("--{}", flag)), - ); + let mut styled_suggestion = StyledStr::new(); + styled_suggestion.none("Did you mean to put '"); + styled_suggestion.good("--"); + styled_suggestion.good(flag); + styled_suggestion.none("' after the subcommand '"); + styled_suggestion.good(sub); + styled_suggestion.none("'?"); + suggestions.push(styled_suggestion); } Some((flag, None)) => { err = err.insert_context_unchecked(