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