From 536c290dfbe6e0741c56f33659563c528c9f09b1 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 28 Jun 2020 19:09:32 +0200 Subject: commands: open and close the backend in a single place, simplify commands --- commands/label.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'commands/label.go') diff --git a/commands/label.go b/commands/label.go index e48be18e..de7bdb3a 100644 --- a/commands/label.go +++ b/commands/label.go @@ -3,18 +3,17 @@ 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" ) func newLabelCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "label []", - Short: "Display, add or remove labels to/from a bug.", - PreRunE: loadRepo(env), + Use: "label []", + Short: "Display, add or remove labels to/from a bug.", + PreRunE: loadBackend(env), + PostRunE: closeBackend(env), RunE: func(cmd *cobra.Command, args []string) error { return runLabel(env, args) }, @@ -27,14 +26,7 @@ func newLabelCommand() *cobra.Command { } func runLabel(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 } -- cgit