InstallShellCompletion installs shell completion for the detected shell
(verbose bool, rootCmd CommandProvider)
| 89 | |
| 90 | // InstallShellCompletion installs shell completion for the detected shell |
| 91 | func InstallShellCompletion(verbose bool, rootCmd CommandProvider) error { |
| 92 | shellCompletionLog.Print("Starting shell completion installation") |
| 93 | |
| 94 | // Type assert rootCmd to *cobra.Command to access additional methods if needed |
| 95 | // For now, we only use the CommandProvider interface methods |
| 96 | cmd, ok := rootCmd.(*cobra.Command) |
| 97 | if !ok { |
| 98 | return errors.New("rootCmd must be a *cobra.Command") |
| 99 | } |
| 100 | |
| 101 | shellType := DetectShell() |
| 102 | shellCompletionLog.Printf("Detected shell type: %s", shellType) |
| 103 | |
| 104 | if shellType == ShellUnknown { |
| 105 | return errors.New("could not detect shell type. Please install completions manually using: gh aw completion <shell>") |
| 106 | } |
| 107 | |
| 108 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Detected shell: %s", shellType))) |
| 109 | |
| 110 | switch shellType { |
| 111 | case ShellBash: |
| 112 | return installBashCompletion(verbose, cmd) |
| 113 | case ShellZsh: |
| 114 | return installZshCompletion(verbose, cmd) |
| 115 | case ShellFish: |
| 116 | return installFishCompletion(verbose, cmd) |
| 117 | case ShellPowerShell: |
| 118 | return installPowerShellCompletion(verbose, cmd) |
| 119 | default: |
| 120 | return fmt.Errorf("shell completion not supported for: %s", shellType) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // installBashCompletion installs bash completion |
| 125 | func installBashCompletion(verbose bool, cmd *cobra.Command) error { |