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/push.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'commands/push.go') diff --git a/commands/push.go b/commands/push.go index fee8a50d..f4b83fab 100644 --- a/commands/push.go +++ b/commands/push.go @@ -4,18 +4,16 @@ import ( "errors" "github.com/spf13/cobra" - - "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/util/interrupt" ) func newPushCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "push []", - Short: "Push bugs update to a git remote.", - PreRunE: loadRepo(env), + Use: "push []", + Short: "Push bugs update to a git remote.", + PreRunE: loadBackend(env), + PostRunE: closeBackend(env), RunE: func(cmd *cobra.Command, args []string) error { return runPush(env, args) }, @@ -34,14 +32,7 @@ func runPush(env *Env, args []string) error { remote = args[0] } - backend, err := cache.NewRepoCache(env.repo) - if err != nil { - return err - } - defer backend.Close() - interrupt.RegisterCleaner(backend.Close) - - stdout, err := backend.Push(remote) + stdout, err := env.backend.Push(remote) if err != nil { return err } -- cgit