-
Notifications
You must be signed in to change notification settings - Fork 0
/
completion.go
47 lines (39 loc) · 894 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 (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
const (
defaultShell = "zsh"
)
var (
shell string
)
func init() {
completionCmd.Flags().StringVar(&shell, "shell", defaultShell, "desired shell to generate completions for")
}
var completionCmd = &cobra.Command{
Use: "completion",
Short: "Generate completion files for the align cli",
Run: completionFunc,
}
func completionFunc(cmd *cobra.Command, args []string) {
var err error
switch strings.ToLower(shell) {
case "bash":
err = rootCmd.GenBashCompletion(os.Stdout)
case "fish":
err = rootCmd.GenFishCompletion(os.Stdout, false)
case "ps", "powershell", "power_shell":
err = rootCmd.GenPowerShellCompletion(os.Stdout)
case "zsh":
err = rootCmd.GenZshCompletion(os.Stdout)
default:
}
if err != nil {
fmt.Printf("error generating completion output: %v", err.Error())
os.Exit(1)
}
}