diff options
author | Michael Muré <batolettre@gmail.com> | 2020-06-28 18:26:29 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-06-28 18:26:29 +0200 |
commit | 26bd1dd11010b4d86cebe2510ad7085a6b316334 (patch) | |
tree | f1fe939311c75bd615071e96f3d37822cccd77a7 /commands/deselect.go | |
parent | c0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff) | |
download | git-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz |
commands: refactor to avoid globals
Diffstat (limited to 'commands/deselect.go')
-rw-r--r-- | commands/deselect.go | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/commands/deselect.go b/commands/deselect.go index f92c81fd..22a5f55d 100644 --- a/commands/deselect.go +++ b/commands/deselect.go @@ -1,14 +1,35 @@ package commands import ( + "github.com/spf13/cobra" + "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/interrupt" - "github.com/spf13/cobra" ) -func runDeselect(cmd *cobra.Command, args []string) error { - backend, err := cache.NewRepoCache(repo) +func newDeselectCommand() *cobra.Command { + env := newEnv() + + cmd := &cobra.Command{ + Use: "deselect", + Short: "Clear the implicitly selected bug.", + Example: `git bug select 2f15 +git bug comment +git bug status +git bug deselect +`, + PreRunE: loadRepo(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runDeselect(env) + }, + } + + return cmd +} + +func runDeselect(env *Env) error { + backend, err := cache.NewRepoCache(env.repo) if err != nil { return err } @@ -22,20 +43,3 @@ func runDeselect(cmd *cobra.Command, args []string) error { return nil } - -var deselectCmd = &cobra.Command{ - Use: "deselect", - Short: "Clear the implicitly selected bug.", - Example: `git bug select 2f15 -git bug comment -git bug status -git bug deselect -`, - PreRunE: loadRepo, - RunE: runDeselect, -} - -func init() { - RootCmd.AddCommand(deselectCmd) - deselectCmd.Flags().SortFlags = false -} |