get.porter.sh/porter@v1.3.0/cmd/porter/completion.go (about) 1 package main 2 3 import ( 4 "get.porter.sh/porter/pkg/porter" 5 "github.com/spf13/cobra" 6 ) 7 8 func buildCompletionCommand(p *porter.Porter) *cobra.Command { 9 10 cmd := &cobra.Command{ 11 Use: "completion [bash|zsh|fish|powershell]", 12 Short: "Generate completion script", 13 Long: `Save the output of this command to a file and load the file into your shell. 14 For additional details see: https://porter.sh/install#command-completion`, 15 Example: "porter completion bash > /usr/local/etc/bash_completions.d/porter", 16 DisableFlagsInUseLine: true, 17 ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, 18 Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), 19 RunE: func(cmd *cobra.Command, args []string) error { 20 switch args[0] { 21 case "bash": 22 return cmd.Root().GenBashCompletion(p.Out) 23 case "zsh": 24 return cmd.Root().GenZshCompletion(p.Out) 25 case "fish": 26 return cmd.Root().GenFishCompletion(p.Out, true) 27 case "powershell": 28 return cmd.Root().GenPowerShellCompletionWithDesc(p.Out) 29 } 30 return nil 31 }, 32 } 33 cmd.Annotations = map[string]string{ 34 "group": "meta", 35 skipConfig: "", 36 } 37 return cmd 38 }