-
Notifications
You must be signed in to change notification settings - Fork 232
/
completion.go
47 lines (40 loc) · 895 Bytes
/
completion.go
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
44
45
46
47
package cmd
import (
"os"
"github.com/spf13/cobra"
)
func newCompletionCommand() *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generate shell completion scripts",
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
panic(err)
}
},
}
bashCommand := &cobra.Command{
Use: "bash",
Short: "Generate bash completion scripts",
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Root().GenBashCompletion(os.Stdout)
if err != nil {
panic(err)
}
},
}
zshCommand := &cobra.Command{
Use: "zsh",
Short: "Generate zsh completion scripts",
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Root().GenZshCompletion(os.Stdout)
if err != nil {
panic(err)
}
},
}
completionCmd.AddCommand(bashCommand)
completionCmd.AddCommand(zshCommand)
return completionCmd
}