From e377f1c02a50582f9aaf22d661eb732f9f2d5c29 Mon Sep 17 00:00:00 2001 From: Shai Nagar Date: Tue, 21 Sep 2021 18:48:40 +0300 Subject: [PATCH] reusing shared code from sha1n/gommons (#154) --- cmd/main.go | 3 ++- go.mod | 2 +- go.sum | 3 ++- internal/cli/completion.go | 32 -------------------------------- 4 files changed, 5 insertions(+), 35 deletions(-) delete mode 100644 internal/cli/completion.go diff --git a/cmd/main.go b/cmd/main.go index 1ebfa95..8edbdc9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,6 +10,7 @@ import ( "github.com/sha1n/bert/api" "github.com/sha1n/bert/internal/cli" "github.com/sha1n/bert/pkg/osutil" + "github.com/sha1n/gommons/pkg/cmd" errorhandling "github.com/sha1n/gommons/pkg/error_handling" "github.com/sha1n/termite" log "github.com/sirupsen/logrus" @@ -49,7 +50,7 @@ func doRun(exitFn func(int)) { // Subcommands rootCmd.AddCommand(cli.CreateConfigCommand(ctx)) - rootCmd.AddCommand(cli.CreateCompletionCommand()) + rootCmd.AddCommand(cmd.CreateShellCompletionScriptGenCommand()) if enableSelfUpdate() { rootCmd.AddCommand(cli.CreateUpdateCommand(Version, ProgramName, ctx)) } diff --git a/go.mod b/go.mod index f49d712..02039a4 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-playground/universal-translator v0.18.0 github.com/go-playground/validator/v10 v10.9.0 github.com/montanaflynn/stats v0.6.6 - github.com/sha1n/gommons v0.0.9 + github.com/sha1n/gommons v0.0.10 github.com/sha1n/termite v0.0.19 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.2.1 diff --git a/go.sum b/go.sum index 03d71f6..88f2a60 100644 --- a/go.sum +++ b/go.sum @@ -289,8 +289,9 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/sha1n/gommons v0.0.9 h1:q8UXAuo1rkMDS7XtJU+hl6jyatSyQCZdJ4p91lvzzzA= github.com/sha1n/gommons v0.0.9/go.mod h1:d9PBtenEZe6G9w1NftkbRpc2ISyJdw57wmnUKNT0wnM= +github.com/sha1n/gommons v0.0.10 h1:SUPfx0aSG+9Rhok1V+UevwpYhn9P0WI3Mm9GJPuM9kQ= +github.com/sha1n/gommons v0.0.10/go.mod h1:ioZhUOTBogxTZD57BVlxThZs4SIw8jS/nX9hgQ1lbn8= github.com/sha1n/termite v0.0.19 h1:zx7Vdp6ZPbONLZ7+VcdLHTr5JkUmO1z0mMpURwkOwO8= github.com/sha1n/termite v0.0.19/go.mod h1:wuukS1dnke28CUEgrlKXoLXdTXcjwTFl0Q4S9luPiuA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= diff --git a/internal/cli/completion.go b/internal/cli/completion.go deleted file mode 100644 index 57490f4..0000000 --- a/internal/cli/completion.go +++ /dev/null @@ -1,32 +0,0 @@ -package cli - -import ( - "os" - - "github.com/spf13/cobra" -) - -// CreateCompletionCommand generates completion shell scripts -func CreateCompletionCommand() *cobra.Command { - return &cobra.Command{ - Use: "completion [bash|zsh|fish|powershell]", - Short: "Generate completion script", - Long: "To load completions", - DisableFlagsInUseLine: true, - ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, - Args: cobra.ExactValidArgs(1), - Hidden: true, - Run: func(cmd *cobra.Command, args []string) { - switch args[0] { - case "bash": - cmd.Root().GenBashCompletion(os.Stdout) - case "zsh": - cmd.Root().GenZshCompletion(os.Stdout) - case "fish": - cmd.Root().GenFishCompletion(os.Stdout, true) - case "powershell": - cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout) - } - }, - } -}