From fa60e723fc9cc05d2ac07d6d867a60351bf9ef6a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 27 Mar 2023 20:41:21 -0500 Subject: [PATCH] fix(error): Give more idea why we are suggesting an arg One challenge with this is finding something that generally works. Making this work perfectly for one setting will make it inconsistent with other settings and take up more binary size / compile time. So in the end, I felt like just mirroring rustc (with a bit more brevity) seemed like a decent experiment. This will be evaluated by the feedback on release. This is a small part of #4638 --- clap_builder/src/error/format.rs | 24 +++++++++++------------- tests/builder/opts.rs | 4 ++-- tests/builder/possible_values.rs | 8 ++++---- tests/builder/subcommands.rs | 6 +++--- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/clap_builder/src/error/format.rs b/clap_builder/src/error/format.rs index 6023b5c53ae..9f11846b1f7 100644 --- a/clap_builder/src/error/format.rs +++ b/clap_builder/src/error/format.rs @@ -429,19 +429,22 @@ fn try_help(styled: &mut StyledStr, help: Option<&str>) { fn did_you_mean(styled: &mut StyledStr, context: &str, valid: &ContextValue) { if let ContextValue::String(valid) = valid { styled.none(TAB); - styled.good("tip: "); + styled.good("tip: a similar "); styled.none(context); - styled.none(" '"); + styled.none(" exists: '"); styled.good(valid); - styled.none("' exists"); + styled.none("'"); } else if let ContextValue::Strings(valid) = valid { styled.none(TAB); - styled.good("tip: "); - styled.none(context); - if valid.len() > 1 { - styled.none("s"); + if valid.len() == 1 { + styled.good("tip: a similar "); + styled.none(context); + styled.none(" exists: "); + } else { + styled.good("tip: some similar "); + styled.none(context); + styled.none("s exist: "); } - styled.none(" "); for (i, valid) in valid.iter().enumerate() { if i != 0 { styled.none(", "); @@ -450,11 +453,6 @@ fn did_you_mean(styled: &mut StyledStr, context: &str, valid: &ContextValue) { styled.good(valid); styled.none("'"); } - if valid.len() == 1 { - styled.none(" exists"); - } else { - styled.none(" exist"); - } } } diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs index 8ca719663a4..7e61b763043 100644 --- a/tests/builder/opts.rs +++ b/tests/builder/opts.rs @@ -448,7 +448,7 @@ fn did_you_mean() { static DYM: &str = "\ error: unexpected argument '--optio' found - tip: argument '--option' exists + tip: a similar argument exists: '--option' Usage: clap-test --option ... [positional] [positional2] [positional3]... @@ -546,7 +546,7 @@ fn issue_1073_suboptimal_flag_suggestion() { static DYM_ISSUE_1073: &str = "\ error: unexpected argument '--files-without-matches' found - tip: argument '--files-without-match' exists + tip: a similar argument exists: '--files-without-match' Usage: ripgrep-616 --files-without-match diff --git a/tests/builder/possible_values.rs b/tests/builder/possible_values.rs index eb3058d4fa9..b39517279be 100644 --- a/tests/builder/possible_values.rs +++ b/tests/builder/possible_values.rs @@ -181,7 +181,7 @@ fn possible_values_output() { error: invalid value 'slo' for '-O