feat: add sub-command to generate completions
This commit is contained in:
parent
6e6a1cbbb6
commit
93bbc9d6b9
34
cli/completion/daemon.go
Normal file
34
cli/completion/daemon.go
Normal file
@ -0,0 +1,34 @@
|
||||
package completion
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// InitCmd initialize all daemon subcommands
|
||||
func InitCmd(cmd *cobra.Command) error {
|
||||
completionCmd := &cobra.Command{
|
||||
Use: "completion",
|
||||
Short: "Generate completion script",
|
||||
Example: "flucky completion [bash|zsh|fish]",
|
||||
ValidArgs: []string{"bash", "zsh", "fish"},
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
RunE: run,
|
||||
}
|
||||
cmd.AddCommand(completionCmd)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) error {
|
||||
switch args[0] {
|
||||
case "bash":
|
||||
return cmd.Root().GenBashCompletion(os.Stdout)
|
||||
case "zsh":
|
||||
return cmd.Root().GenZshCompletion(os.Stdout)
|
||||
case "fish":
|
||||
return cmd.Root().GenFishCompletion(os.Stdout, true)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"git.cryptic.systems/volker.raschek/flucky/cli/completion"
|
||||
"git.cryptic.systems/volker.raschek/flucky/cli/daemon"
|
||||
imp "git.cryptic.systems/volker.raschek/flucky/cli/imp"
|
||||
"git.cryptic.systems/volker.raschek/flucky/cli/sensor"
|
||||
@ -23,8 +24,7 @@ import (
|
||||
func Execute(version *semver.Version) error {
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "flucky",
|
||||
// Short: "flucky - operate with differen sensors, his values and remote servers to synchronize measured values",
|
||||
Use: "flucky",
|
||||
PersistentPreRunE: preRunError,
|
||||
Version: version.String(),
|
||||
}
|
||||
@ -38,6 +38,7 @@ func Execute(version *semver.Version) error {
|
||||
rootCmd.PersistentFlags().String("loglevel", "info", "Set the Loglevel. Possible values: debug, info, warn, error, fatal")
|
||||
|
||||
subCommands := []func(cmd *cobra.Command) error{
|
||||
completion.InitCmd,
|
||||
daemon.InitCmd,
|
||||
imp.InitCmd,
|
||||
sensor.InitCmd,
|
||||
|
Loading…
Reference in New Issue
Block a user