...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package cmd
17
18 import (
19 "os"
20
21 "github.com/spf13/cobra"
22 )
23
24
25 var completionCmd = &cobra.Command{
26 Use: "completion [bash|zsh|fish|powershell]",
27 Short: "Generate completion script",
28 Long: `To load completions:
29
30 Bash:
31
32 $ source <(chaosctl completion bash)
33
34 # To load completions for each session, execute once:
35 Linux:
36 $ ./bin/chaosctl completion bash > /etc/bash_completion.d/chaosctl
37 MacOS:
38 $ ./bin/chaosctl completion bash > /usr/local/etc/bash_completion.d/chaosctl
39
40 Zsh:
41
42 $ compdef _chaosctl ./bin/chaosctl
43
44 # If shell completion is not already enabled in your environment you will need
45 # to enable it. You can execute the following once:
46
47 $ echo "autoload -U compinit; compinit" >> ~/.zshrc
48
49 # To load completions for each session, execute once:
50 $ ./bin/chaosctl completion zsh > "${fpath[1]}/_chaosctl"
51
52 # You will need to start a new shell for this setup to take effect.
53
54 Fish:
55
56 $ ./bin/chaosctl completion fish | source
57
58 # To load completions for each session, execute once:
59 $ ./bin/chaosctl completion fish > ~/.config/fish/completions/chaosctl.fish
60
61 Powershell:
62
63 PS> ./bin/chaosctl completion powershell | Out-String | Invoke-Expression
64
65 # To load completions for every new session, run:
66 PS> ./bin/chaosctl completion powershell > chaosctl.ps1
67 # and source this file from your powershell profile.
68 `,
69 DisableFlagsInUseLine: true,
70 ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
71 Args: cobra.ExactValidArgs(1),
72 Run: func(cmd *cobra.Command, args []string) {
73 switch args[0] {
74 case "bash":
75 cmd.Root().GenBashCompletion(os.Stdout)
76 case "zsh":
77 cmd.Root().GenZshCompletion(os.Stdout)
78 case "fish":
79 cmd.Root().GenFishCompletion(os.Stdout, true)
80
81
82 case "powershell":
83 cmd.Root().GenPowerShellCompletion(os.Stdout)
84 }
85 },
86 }
87