refac(cmd): mergeing, ordering and outsourcing cmd subcommands

This commit is contained in:
2020-01-13 22:26:41 +01:00
parent 0261203395
commit 0765bd29d1
34 changed files with 1209 additions and 1302 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}