mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
Replace docopt-go with spf13/cobra, giving cheat a built-in `--completion` flag that dynamically generates shell completions for bash, zsh, fish, and powershell. This replaces the manually-maintained static completion scripts and resolves the root cause of multiple completion issues (#768, #705, #633, #632, #476). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 lines
480 B
Go
26 lines
480 B
Go
package completions
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Paths provides completion for the --path flag.
|
|
func Paths(
|
|
_ *cobra.Command,
|
|
_ []string,
|
|
_ string,
|
|
) ([]string, cobra.ShellCompDirective) {
|
|
|
|
conf, err := loadConfig()
|
|
if err != nil {
|
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
|
}
|
|
|
|
names := make([]string, 0, len(conf.Cheatpaths))
|
|
for _, cp := range conf.Cheatpaths {
|
|
names = append(names, cp.Name)
|
|
}
|
|
|
|
return names, cobra.ShellCompDirectiveNoFileComp
|
|
}
|