diff --git a/cmd/completion/bash.go b/cmd/completion/bash.go new file mode 100644 index 0000000..c653788 --- /dev/null +++ b/cmd/completion/bash.go @@ -0,0 +1,20 @@ +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) +} diff --git a/cmd/completion/completion.go b/cmd/completion/completion.go new file mode 100644 index 0000000..e56a3a1 --- /dev/null +++ b/cmd/completion/completion.go @@ -0,0 +1,22 @@ +package completion + +import ( + "github.com/spf13/cobra" +) + +var ( + rootCmd *cobra.Command +) + +var completionCmd = &cobra.Command{ + Use: "completion", + Short: "Generates a shell completion file", +} + +// InitCmd initialize the subcommand +func InitCmd(cmd *cobra.Command) { + cmd.AddCommand(completionCmd) + + rootCmd = cmd + +} diff --git a/cmd/completion/zsh.go b/cmd/completion/zsh.go new file mode 100644 index 0000000..5bc7fb6 --- /dev/null +++ b/cmd/completion/zsh.go @@ -0,0 +1,20 @@ +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) +} diff --git a/cmd/cmd.go b/cmd/root.go similarity index 96% rename from cmd/cmd.go rename to cmd/root.go index c41ad16..a3da44e 100644 --- a/cmd/cmd.go +++ b/cmd/root.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Masterminds/semver" + "github.com/go-flucky/flucky/cmd/completion" "github.com/go-flucky/flucky/cmd/compression" "github.com/go-flucky/flucky/cmd/convert" "github.com/go-flucky/flucky/cmd/daemon" @@ -68,6 +69,7 @@ func Execute(version *semver.Version) { rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file") + completion.InitCmd(rootCmd) compression.InitCmd(rootCmd, &configFile, version) convert.InitCmd(rootCmd, &configFile, version) daemon.InitCmd(rootCmd, &configFile, version)