NewCompletionCommand creates the completion command with install subcommand
()
| 12 | |
| 13 | // NewCompletionCommand creates the completion command with install subcommand |
| 14 | func NewCompletionCommand() *cobra.Command { |
| 15 | cmd := &cobra.Command{ |
| 16 | Use: "completion [shell]", |
| 17 | Short: "Generate shell completion scripts for gh aw commands", |
| 18 | Long: `Generate shell completion scripts to enable tab completion for gh aw commands. |
| 19 | |
| 20 | Tab completion provides: |
| 21 | - Command name completion (add, compile, run, etc.) |
| 22 | - Workflow name completion for commands that accept workflow arguments |
| 23 | - Engine name completion for --engine flag (copilot, claude, codex, gemini, crush) |
| 24 | - Directory path completion for --dir flag |
| 25 | - Helpful descriptions for workflows when available |
| 26 | |
| 27 | Supported shells: bash, zsh, fish, PowerShell`, |
| 28 | Example: ` # Install completions automatically (detects your shell) |
| 29 | gh aw completion install |
| 30 | |
| 31 | # Generate completion script for bash |
| 32 | gh aw completion bash > ~/.bash_completion.d/gh-aw |
| 33 | source ~/.bash_completion.d/gh-aw |
| 34 | |
| 35 | # Generate completion script for zsh |
| 36 | gh aw completion zsh > "${fpath[1]}/_gh-aw" |
| 37 | compinit |
| 38 | |
| 39 | # Generate completion script for fish |
| 40 | gh aw completion fish > ~/.config/fish/completions/gh-aw.fish |
| 41 | |
| 42 | # Generate completion script for PowerShell |
| 43 | gh aw completion powershell | Out-String | Invoke-Expression |
| 44 | |
| 45 | # Add to PowerShell profile for persistent completions |
| 46 | echo 'gh aw completion powershell | Out-String | Invoke-Expression' >> $PROFILE`, |
| 47 | ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, |
| 48 | Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), |
| 49 | RunE: func(cmd *cobra.Command, args []string) error { |
| 50 | shell := args[0] |
| 51 | completionLog.Printf("Generating %s completion script", shell) |
| 52 | |
| 53 | switch shell { |
| 54 | case "bash": |
| 55 | return cmd.Root().GenBashCompletion(os.Stdout) |
| 56 | case "zsh": |
| 57 | return cmd.Root().GenZshCompletion(os.Stdout) |
| 58 | case "fish": |
| 59 | return cmd.Root().GenFishCompletion(os.Stdout, true) |
| 60 | case "powershell": |
| 61 | return cmd.Root().GenPowerShellCompletion(os.Stdout) |
| 62 | default: |
| 63 | return fmt.Errorf("unsupported shell: %s", shell) |
| 64 | } |
| 65 | }, |
| 66 | } |
| 67 | |
| 68 | // Add install subcommand |
| 69 | installCmd := &cobra.Command{ |
| 70 | Use: "install", |
| 71 | Short: "Install shell completion for the detected shell", |