Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include flag descriptions when using zsh completion #1903

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion help.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
continue
}

usage := ""
if docFlag, ok := flag.(DocGenerationFlag); ok {
usage = docFlag.GetUsage()
}

name := strings.TrimSpace(flag.Names()[0])
// this will get total count utf8 letters in flag name
count := utf8.RuneCountInString(name)
Expand All @@ -206,8 +211,10 @@
// match if last argument matches this flag and it is not repeated
if strings.HasPrefix(name, cur) && cur != name && !cliArgContains(name) {
flagCompletion := fmt.Sprintf("%s%s", strings.Repeat("-", count), name)
if usage != "" && strings.HasSuffix(os.Getenv("SHELL"), "zsh") {
flagCompletion = fmt.Sprintf("%s:%s", flagCompletion, usage)

Check warning on line 215 in help.go

View check run for this annotation

Codecov / codecov/patch

help.go#L215

Added line #L215 was not covered by tests
}
fmt.Fprintln(writer, flagCompletion)

}
}
}
Expand Down
Loading