feat: add sub-command to generate completions
This commit is contained in:
34
cli/completion/daemon.go
Normal file
34
cli/completion/daemon.go
Normal file
@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user