package main import ( "errors" "os" "github.com/spf13/cobra" ) var completionCmd = &cobra.Command{ Use: "completion bash|zsh", Short: "Generate shell completion", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { shell := args[0] switch shell { case "bash": return cmd.Parent().GenBashCompletion(os.Stdout) case "zsh": return cmd.Parent().GenZshCompletion(os.Stdout) default: return errors.New("valid shell are bash or zsh") } }, } func init() { RootCmd.AddCommand(completionCmd) }