diff options
author | Michael Muré <batolettre@gmail.com> | 2020-06-28 19:09:32 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-06-28 19:09:32 +0200 |
commit | 536c290dfbe6e0741c56f33659563c528c9f09b1 (patch) | |
tree | 79ea46f76ac6f69c2e6cbf3323be7c620c39a510 /commands/comment.go | |
parent | 26bd1dd11010b4d86cebe2510ad7085a6b316334 (diff) | |
download | git-bug-536c290dfbe6e0741c56f33659563c528c9f09b1.tar.gz |
commands: open and close the backend in a single place, simplify commands
Diffstat (limited to 'commands/comment.go')
-rw-r--r-- | commands/comment.go | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/commands/comment.go b/commands/comment.go index 82e7d9f6..e81405a6 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -4,19 +4,18 @@ import ( text "github.com/MichaelMure/go-term-text" "github.com/spf13/cobra" - "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/commands/select" "github.com/MichaelMure/git-bug/util/colors" - "github.com/MichaelMure/git-bug/util/interrupt" ) func newCommentCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "comment [<id>]", - Short: "Display or add comments to a bug.", - PreRunE: loadRepo(env), + Use: "comment [<id>]", + Short: "Display or add comments to a bug.", + PreRunE: loadBackend(env), + PostRunE: closeBackend(env), RunE: func(cmd *cobra.Command, args []string) error { return runComment(env, args) }, @@ -28,14 +27,7 @@ func newCommentCommand() *cobra.Command { } func runComment(env *Env, args []string) error { - backend, err := cache.NewRepoCache(env.repo) - if err != nil { - return err - } - defer backend.Close() - interrupt.RegisterCleaner(backend.Close) - - b, args, err := _select.ResolveBug(backend, args) + b, args, err := _select.ResolveBug(env.backend, args) if err != nil { return err } |