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>
25 lines
580 B
Go
25 lines
580 B
Go
package completions
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Generate writes a shell completion script to the given writer.
|
|
func Generate(cmd *cobra.Command, shell string, w io.Writer) error {
|
|
switch shell {
|
|
case "bash":
|
|
return cmd.Root().GenBashCompletionV2(w, true)
|
|
case "zsh":
|
|
return cmd.Root().GenZshCompletion(w)
|
|
case "fish":
|
|
return cmd.Root().GenFishCompletion(w, true)
|
|
case "powershell":
|
|
return cmd.Root().GenPowerShellCompletionWithDesc(w)
|
|
default:
|
|
return fmt.Errorf("unsupported shell: %s (valid: bash, zsh, fish, powershell)", shell)
|
|
}
|
|
}
|