Files
gems/opal-task/cmd/completion.go
T
joakim feb5406077 feat: add shell completions, command grouping, and dynamic completions
Add completion command for bash/zsh/fish/powershell generation. Organize
help text using Cobra command groups (Task Commands, Reports, Other).
Register dynamic ValidArgsFunction on filter-accepting commands to
suggest +tag and project:name completions from the database.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:59:21 +01:00

49 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate shell completions",
Long: `Generate shell completion scripts for opal.
To load completions:
Bash:
$ source <(opal completion bash)
# To load on startup, add to ~/.bashrc:
$ echo 'source <(opal completion bash)' >> ~/.bashrc
Zsh:
$ source <(opal completion zsh)
# To load on startup, add to ~/.zshrc:
$ echo 'source <(opal completion zsh)' >> ~/.zshrc
Fish:
$ opal completion fish | source
# To load on startup:
$ opal completion fish > ~/.config/fish/completions/opal.fish`,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
rootCmd.GenBashCompletion(os.Stdout)
case "zsh":
rootCmd.GenZshCompletion(os.Stdout)
case "fish":
rootCmd.GenFishCompletion(os.Stdout, true)
case "powershell":
rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
default:
fmt.Fprintf(os.Stderr, "Unknown shell: %s\n", args[0])
os.Exit(1)
}
},
}