refac(cmd): mergeing, ordering and outsourcing cmd subcommands
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
package completion
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var bashCompletionCmd = &cobra.Command{
|
||||
Use: "bash",
|
||||
Short: "Generates a bash completion file",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
rootCmd.GenBashCompletion(os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
completionCmd.AddCommand(bashCompletionCmd)
|
||||
}
|
@ -1,22 +1,42 @@
|
||||
package completion
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
rootCmd *cobra.Command
|
||||
)
|
||||
// InitCmd initialize all completion subcommands
|
||||
func InitCmd(cmd *cobra.Command) error {
|
||||
|
||||
var completionCmd = &cobra.Command{
|
||||
Use: "completion",
|
||||
Short: "Generates a shell completion file",
|
||||
}
|
||||
completionCmd := &cobra.Command{
|
||||
Use: "completion",
|
||||
Short: "Generates a shell completion file",
|
||||
}
|
||||
|
||||
// InitCmd initialize the subcommand
|
||||
func InitCmd(cmd *cobra.Command) {
|
||||
bashCompletionCmd := &cobra.Command{
|
||||
Use: "bash",
|
||||
Short: "Generates a bash completion file",
|
||||
Args: cobra.NoArgs,
|
||||
Example: "flucky completion bash",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.GenBashCompletion(os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
zshCompletionCmd := &cobra.Command{
|
||||
Use: "zsh",
|
||||
Short: "Generate a zsh completion file",
|
||||
Args: cobra.NoArgs,
|
||||
Example: "flucky completion zsh",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.GenZshCompletion(os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
completionCmd.AddCommand(bashCompletionCmd)
|
||||
completionCmd.AddCommand(zshCompletionCmd)
|
||||
cmd.AddCommand(completionCmd)
|
||||
|
||||
rootCmd = cmd
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
package completion
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var zshCompletionCmd = &cobra.Command{
|
||||
Use: "zsh",
|
||||
Short: "Generate a zsh completion file",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
rootCmd.GenZshCompletion(os.Stdout)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
completionCmd.AddCommand(zshCompletionCmd)
|
||||
}
|
Reference in New Issue
Block a user