MCPcopy Create free account
hub / github.com/github/gh-aw / InstallShellCompletion

Function InstallShellCompletion

pkg/cli/shell_completion.go:91–122  ·  view source on GitHub ↗

InstallShellCompletion installs shell completion for the detected shell

(verbose bool, rootCmd CommandProvider)

Source from the content-addressed store, hash-verified

89
90// InstallShellCompletion installs shell completion for the detected shell
91func 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
125func installBashCompletion(verbose bool, cmd *cobra.Command) error {

Callers 3

InitRepositoryFunction · 0.85
NewCompletionCommandFunction · 0.85

Calls 9

FormatInfoMessageFunction · 0.92
DetectShellFunction · 0.85
installBashCompletionFunction · 0.85
installZshCompletionFunction · 0.85
installFishCompletionFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1