grokkit/cmd/completion.go
Greg Gauthier ec5c43163b
Some checks failed
CI / Test (push) Successful in 26s
CI / Lint (push) Failing after 14s
CI / Build (push) Failing after 31s
refactor(cmd): improve error handling in commands and tests
- Add error checking for filepath.Walk and fmt.Scanln in agent.go
- Ignore MkdirAll error in chat.go, add checks in chat_test.go
- Add Scanln error handling in commit.go
- Capture and exit on completion generation errors in completion.go
- Add WriteFile error checks in edit_test.go
2026-03-01 14:10:24 +00:00

68 lines
1.9 KiB
Go

package cmd
import (
"os"
"github.com/spf13/cobra"
)
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate shell completion script",
Long: `Generate shell completion script for grokkit.
To load completions:
Bash:
$ source <(grokkit completion bash)
# To load completions for each session, execute once:
# Linux:
$ grokkit completion bash > /etc/bash_completion.d/grokkit
# macOS:
$ grokkit completion bash > $(brew --prefix)/etc/bash_completion.d/grokkit
Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ grokkit completion zsh > "${fpath[1]}/_grokkit"
# You will need to start a new shell for this setup to take effect.
Fish:
$ grokkit completion fish | source
# To load completions for each session, execute once:
$ grokkit completion fish > ~/.config/fish/completions/grokkit.fish
PowerShell:
PS> grokkit completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> grokkit completion powershell > grokkit.ps1
# and source this file from your PowerShell profile.
`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
var err error
switch args[0] {
case "bash":
err = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
err = cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
err = cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
err = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
if err != nil {
os.Exit(1)
}
},
}