From 63eec40652b4fc0d9a29c21dc16b0084a4af5ac9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 13 Oct 2022 13:15:11 -0500 Subject: [PATCH] refactor(error): Clarify distinct suggestion cases --- src/error/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/error/mod.rs b/src/error/mod.rs index 913d48181af..4ec2d0cc3f0 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -670,17 +670,24 @@ impl Error { err = err .insert_context_unchecked(ContextKind::Usage, ContextValue::StyledStr(usage)); } - if let Some((flag, sub)) = did_you_mean { - err = err.insert_context_unchecked( - ContextKind::SuggestedArg, - ContextValue::String(format!("--{}", flag)), - ); - if let Some(sub) = sub { + 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)), + ); + } + Some((flag, None)) => { + err = err.insert_context_unchecked( + ContextKind::SuggestedArg, + ContextValue::String(format!("--{}", flag)), + ); } + None => {} } if !suggestions.is_empty() { err = err.insert_context_unchecked(