Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions suggestions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions suggestions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +48,7 @@ func TestSuggestFlag(t *testing.T) {
{"hlp", "--help"},
{"k", ""},
{"s", "-s"},
{"éé", "-é"},
} {
// When
res := suggestFlag(app.Flags, testCase.provided, false)
Expand Down
Loading