-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
completion.go
39 lines (33 loc) · 1.03 KB
/
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
package cmd
import (
"github.com/spf13/cobra"
"os"
u "github.com/cloudposse/atmos/pkg/utils"
)
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script for Bash, Zsh, Fish and PowerShell",
Long: "This command generates completion scripts for Bash, Zsh, Fish and PowerShell",
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
var err error
switch args[0] {
case "bash":
err = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
err = cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
err = cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
err = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
if err != nil {
u.LogErrorAndExit(err)
}
},
}
func init() {
RootCmd.AddCommand(completionCmd)
}