feat(cmd/completion): generate shell completion files
This commit is contained in:
parent
5f48d29dae
commit
111dc0e4f1
20
cmd/completion/bash.go
Normal file
20
cmd/completion/bash.go
Normal 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)
|
||||||
|
}
|
22
cmd/completion/completion.go
Normal file
22
cmd/completion/completion.go
Normal 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
20
cmd/completion/zsh.go
Normal 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)
|
||||||
|
}
|
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
|
"github.com/go-flucky/flucky/cmd/completion"
|
||||||
"github.com/go-flucky/flucky/cmd/compression"
|
"github.com/go-flucky/flucky/cmd/compression"
|
||||||
"github.com/go-flucky/flucky/cmd/convert"
|
"github.com/go-flucky/flucky/cmd/convert"
|
||||||
"github.com/go-flucky/flucky/cmd/daemon"
|
"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")
|
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file")
|
||||||
|
|
||||||
|
completion.InitCmd(rootCmd)
|
||||||
compression.InitCmd(rootCmd, &configFile, version)
|
compression.InitCmd(rootCmd, &configFile, version)
|
||||||
convert.InitCmd(rootCmd, &configFile, version)
|
convert.InitCmd(rootCmd, &configFile, version)
|
||||||
daemon.InitCmd(rootCmd, &configFile, version)
|
daemon.InitCmd(rootCmd, &configFile, version)
|
Loading…
Reference in New Issue
Block a user