Skip to content

Commit 89f102a

Browse files
committed
feat: support flag descriptions for zsh completion
1 parent 043b774 commit 89f102a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

help.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) {
192192
continue
193193
}
194194

195+
usage := ""
196+
if docFlag, ok := flag.(DocGenerationFlag); ok {
197+
usage = docFlag.GetUsage()
198+
}
199+
195200
name := strings.TrimSpace(flag.Names()[0])
196201
// this will get total count utf8 letters in flag name
197202
count := utf8.RuneCountInString(name)
@@ -206,8 +211,10 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) {
206211
// match if last argument matches this flag and it is not repeated
207212
if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(name) {
208213
flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name)
214+
if usage != "" && strings.HasSuffix(os.Getenv("SHELL"), "zsh") {
215+
flagCompletion = fmt.Sprintf("%s:%s", flagCompletion, usage)
216+
}
209217
fmt.Fprintln(writer, flagCompletion)
210-
211218
}
212219
}
213220
}

0 commit comments

Comments
 (0)