aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_configure.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-28 19:09:32 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-28 19:09:32 +0200
commit536c290dfbe6e0741c56f33659563c528c9f09b1 (patch)
tree79ea46f76ac6f69c2e6cbf3323be7c620c39a510 /commands/bridge_configure.go
parent26bd1dd11010b4d86cebe2510ad7085a6b316334 (diff)
downloadgit-bug-536c290dfbe6e0741c56f33659563c528c9f09b1.tar.gz
commands: open and close the backend in a single place, simplify commands
Diffstat (limited to 'commands/bridge_configure.go')
-rw-r--r--commands/bridge_configure.go14
1 files changed, 4 insertions, 10 deletions
diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go
index 83555b0c..ecdb6502 100644
--- a/commands/bridge_configure.go
+++ b/commands/bridge_configure.go
@@ -12,9 +12,7 @@ import (
"github.com/MichaelMure/git-bug/bridge"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bridge/core/auth"
- "github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/repository"
- "github.com/MichaelMure/git-bug/util/interrupt"
)
type bridgeConfigureOptions struct {
@@ -86,7 +84,8 @@ git bug bridge configure \
--target=github \
--url=https://github.com/michaelmure/git-bug \
--token=$(TOKEN)`,
- PreRunE: loadRepo(env),
+ PreRunE: loadBackend(env),
+ PostRunE: closeBackend(env),
RunE: func(cmd *cobra.Command, args []string) error {
return runBridgeConfigure(env, options)
},
@@ -111,12 +110,7 @@ git bug bridge configure \
}
func runBridgeConfigure(env *Env, opts bridgeConfigureOptions) error {
- backend, err := cache.NewRepoCache(env.repo)
- if err != nil {
- return err
- }
- defer backend.Close()
- interrupt.RegisterCleaner(backend.Close)
+ var err error
if (opts.tokenStdin || opts.token != "" || opts.params.CredPrefix != "") &&
(opts.name == "" || opts.target == "") {
@@ -156,7 +150,7 @@ func runBridgeConfigure(env *Env, opts bridgeConfigureOptions) error {
}
}
- b, err := bridge.NewBridge(backend, opts.target, opts.name)
+ b, err := bridge.NewBridge(env.backend, opts.target, opts.name)
if err != nil {
return err
}