package cmd import ( "fmt" "io" "os" "github.com/spf13/cobra" ) var completionCmd = &cobra.Command{ Use: "completion [bash|zsh|fish|powershell]", Short: "Generate shell completion scripts", Long: "Generate shell completion scripts for fj.", Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, DisableFlagsInUseLine: true, RunE: func(cmd *cobra.Command, args []string) error { var out io.Writer = os.Stdout switch args[0] { case "bash": return rootCmd.GenBashCompletion(out) case "zsh": return rootCmd.GenZshCompletion(out) case "fish": return rootCmd.GenFishCompletion(out, true) case "powershell": return rootCmd.GenPowerShellCompletionWithDesc(out) default: return fmt.Errorf("unsupported shell: %s", args[0]) } }, } func init() { rootCmd.AddCommand(completionCmd) }