package completion import ( "os" "github.com/spf13/cobra" ) // InitCmd initialize all daemon subcommands func InitCmd(cmd *cobra.Command) error { completionCmd := &cobra.Command{ Use: "completion", Short: "Generate completion script", Example: "flucky completion [bash|zsh|fish]", ValidArgs: []string{"bash", "zsh", "fish"}, Args: cobra.ExactValidArgs(1), RunE: run, } cmd.AddCommand(completionCmd) return nil } func run(cmd *cobra.Command, args []string) error { switch args[0] { case "bash": return cmd.Root().GenBashCompletion(os.Stdout) case "zsh": return cmd.Root().GenZshCompletion(os.Stdout) case "fish": return cmd.Root().GenFishCompletion(os.Stdout, true) } return nil }