feat(cmd/completion): generate shell completion files

This commit is contained in:
Markus Pesch 2020-01-08 21:54:15 +01:00
parent 5f48d29dae
commit 111dc0e4f1
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
4 changed files with 64 additions and 0 deletions

20
cmd/completion/bash.go Normal file
View File

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

View File

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

20
cmd/completion/zsh.go Normal file
View File

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

View File

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