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/ls-id.go | |
parent | c0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff) | |
download | git-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz |
commands: refactor to avoid globals
Diffstat (limited to 'commands/ls-id.go')
-rw-r--r-- | commands/ls-id.go | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/commands/ls-id.go b/commands/ls-id.go index 22357eb4..6624793d 100644 --- a/commands/ls-id.go +++ b/commands/ls-id.go @@ -1,17 +1,29 @@ package commands import ( - "fmt" - "github.com/spf13/cobra" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/util/interrupt" ) -func runLsID(cmd *cobra.Command, args []string) error { +func newLsIdCommand() *cobra.Command { + env := newEnv() + + cmd := &cobra.Command{ + Use: "ls-id [<prefix>]", + Short: "List bug identifiers.", + PreRunE: loadRepo(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runLsId(env, args) + }, + } + + return cmd +} - backend, err := cache.NewRepoCache(repo) +func runLsId(env *Env, args []string) error { + backend, err := cache.NewRepoCache(env.repo) if err != nil { return err } @@ -25,20 +37,9 @@ func runLsID(cmd *cobra.Command, args []string) error { for _, id := range backend.AllBugsIds() { if prefix == "" || id.HasPrefix(prefix) { - fmt.Println(id) + env.out.Println(id) } } return nil } - -var listBugIDCmd = &cobra.Command{ - Use: "ls-id [<prefix>]", - Short: "List bug identifiers.", - PreRunE: loadRepo, - RunE: runLsID, -} - -func init() { - RootCmd.AddCommand(listBugIDCmd) -} |