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/select.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'commands/select.go') diff --git a/commands/select.go b/commands/select.go index e4916650..f2cf2d47 100644 --- a/commands/select.go +++ b/commands/select.go @@ -5,9 +5,7 @@ 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 newSelectCommand() *cobra.Command { @@ -29,7 +27,8 @@ instead of The complementary command is "git bug deselect" performing the opposite operation. `, - PreRunE: loadRepo(env), + PreRunE: loadBackend(env), + PostRunE: closeBackend(env), RunE: func(cmd *cobra.Command, args []string) error { return runSelect(env, args) }, @@ -43,21 +42,14 @@ func runSelect(env *Env, args []string) error { return errors.New("You must provide a bug id") } - backend, err := cache.NewRepoCache(env.repo) - if err != nil { - return err - } - defer backend.Close() - interrupt.RegisterCleaner(backend.Close) - prefix := args[0] - b, err := backend.ResolveBugPrefix(prefix) + b, err := env.backend.ResolveBugPrefix(prefix) if err != nil { return err } - err = _select.Select(backend, b.Id()) + err = _select.Select(env.backend, b.Id()) if err != nil { return err } -- cgit