forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletion.go
More file actions
43 lines (35 loc) · 938 Bytes
/
completion.go
File metadata and controls
43 lines (35 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package command
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(completionCmd)
completionCmd.Flags().StringP("shell", "s", "bash", "The type of shell")
}
var completionCmd = &cobra.Command{
Use: "completion",
Hidden: true,
Short: "Generates completion scripts",
Long: `To enable completion in your shell, run:
eval "$(gh completion)"
You can add that to your '~/.bash_profile' to enable completion whenever you
start a new shell.
When installing with Homebrew, see https://docs.brew.sh/Shell-Completion
`,
RunE: func(cmd *cobra.Command, args []string) error {
shellType, err := cmd.Flags().GetString("shell")
if err != nil {
return err
}
switch shellType {
case "bash":
RootCmd.GenBashCompletion(cmd.OutOrStdout())
case "zsh":
RootCmd.GenZshCompletion(cmd.OutOrStdout())
default:
return fmt.Errorf("unsupported shell type: %s", shellType)
}
return nil
},
}