bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/cmd/synsec-cli/completion.go (about) 1 package main 2 3 import ( 4 "os" 5 6 "github.com/spf13/cobra" 7 ) 8 9 func NewCompletionCmd() *cobra.Command { 10 11 var completionCmd = &cobra.Command{ 12 Use: "completion [bash|zsh]", 13 Short: "Generate completion script", 14 Long: `To load completions: 15 16 ### Bash: 17 18 $ source <(ccscli completion bash) 19 20 # To load completions for each session, execute once: 21 22 23 # Linux: 24 25 $ ccscli completion bash | sudo tee /etc/bash_completion.d/ccscli 26 27 # macOS: 28 29 $ ccscli completion bash | sudo tee /usr/local/etc/bash_completion.d/ccscli 30 31 ### Zsh: 32 33 # If shell completion is not already enabled in your environment, 34 # you will need to enable it. You can execute the following once: 35 36 $ echo "autoload -U compinit; compinit" >> ~/.zshrc 37 38 # To load completions for each session, execute once: 39 40 $ ccscli completion zsh > "${fpath[1]}/_ccscli" 41 42 # You will need to start a new shell for this setup to take effect. 43 `, 44 DisableFlagsInUseLine: true, 45 ValidArgs: []string{"bash", "zsh"}, 46 Args: cobra.ExactValidArgs(1), 47 Run: func(cmd *cobra.Command, args []string) { 48 switch args[0] { 49 case "bash": 50 cmd.Root().GenBashCompletion(os.Stdout) 51 case "zsh": 52 cmd.Root().GenZshCompletion(os.Stdout) 53 /*case "fish": 54 cmd.Root().GenFishCompletion(os.Stdout, true) 55 */ 56 } 57 }, 58 } 59 return completionCmd 60 }