diff --git a/suggestions.go b/suggestions.go index 401dcef253..4c1ce9aadb 100644 --- a/suggestions.go +++ b/suggestions.go @@ -120,13 +120,14 @@ func suggestFlag(flags []Flag, provided string, hideHelp bool) string { } } - if len(suggestion) == 1 { - suggestion = "-" + suggestion - } else if len(suggestion) > 1 { - suggestion = "--" + suggestion + if len(suggestion) == 0 { + return "" } - return suggestion + // Use the same rune-counting rule that drives the help output + // (prefixFor) so that a single-rune name is suggested as a short flag + // regardless of how many bytes that rune is encoded in. + return prefixFor(suggestion) + suggestion } // suggestCommand takes a list of commands and a provided string to suggest a diff --git a/suggestions_test.go b/suggestions_test.go index b1e962104e..67fe3c1b4a 100644 --- a/suggestions_test.go +++ b/suggestions_test.go @@ -38,6 +38,7 @@ func TestJaroWinkler(t *testing.T) { func TestSuggestFlag(t *testing.T) { // Given app := buildExtendedTestCommand() + app.Flags = append(app.Flags, &BoolFlag{Name: "é"}) for _, testCase := range []struct { provided, expected string @@ -47,6 +48,7 @@ func TestSuggestFlag(t *testing.T) { {"hlp", "--help"}, {"k", ""}, {"s", "-s"}, + {"éé", "-é"}, } { // When res := suggestFlag(app.Flags, testCase.provided, false)