/
completion.go
37 lines (33 loc) · 973 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
package cmd
import (
"os"
"github.com/appgate/sdpctl/pkg/docs"
"github.com/spf13/cobra"
)
// NewCmdCompletion represents the completion command
func NewCmdCompletion() *cobra.Command {
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Annotations: map[string]string{
"skipAuthCheck": "true",
},
Short: docs.CompletionDocs.Short,
Long: docs.CompletionDocs.Long,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Example: docs.CompletionDocs.ExampleString(),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}
return completionCmd
}