mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 03:03:32 +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>
39 lines
760 B
Go
39 lines
760 B
Go
package completions
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"github.com/mitchellh/go-homedir"
|
|
|
|
"github.com/cheat/cheat/internal/config"
|
|
)
|
|
|
|
// loadConfig loads the cheat configuration for use in completion functions.
|
|
// It returns an error rather than exiting, since completions should degrade
|
|
// gracefully.
|
|
func loadConfig() (config.Config, error) {
|
|
home, err := homedir.Dir()
|
|
if err != nil {
|
|
return config.Config{}, err
|
|
}
|
|
|
|
envvars := config.EnvVars()
|
|
|
|
confpaths, err := config.Paths(runtime.GOOS, home, envvars)
|
|
if err != nil {
|
|
return config.Config{}, err
|
|
}
|
|
|
|
confpath, err := config.Path(confpaths)
|
|
if err != nil {
|
|
return config.Config{}, err
|
|
}
|
|
|
|
conf, err := config.New(confpath, true)
|
|
if err != nil {
|
|
return config.Config{}, err
|
|
}
|
|
|
|
return conf, nil
|
|
}
|