aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_rm.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-28 18:26:29 +0200
commit26bd1dd11010b4d86cebe2510ad7085a6b316334 (patch)
treef1fe939311c75bd615071e96f3d37822cccd77a7 /commands/bridge_rm.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/bridge_rm.go')
-rw-r--r--commands/bridge_rm.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/commands/bridge_rm.go b/commands/bridge_rm.go
index 76ad5949..4ff963db 100644
--- a/commands/bridge_rm.go
+++ b/commands/bridge_rm.go
@@ -1,8 +1,6 @@
package commands
import (
- "fmt"
-
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/bridge"
@@ -10,8 +8,24 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func runBridgeRm(cmd *cobra.Command, args []string) error {
- backend, err := cache.NewRepoCache(repo)
+func newBridgeRm() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "rm <name>",
+ Short: "Delete a configured bridge.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runBridgeRm(env, args)
+ },
+ Args: cobra.ExactArgs(1),
+ }
+
+ return cmd
+}
+
+func runBridgeRm(env *Env, args []string) error {
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -23,18 +37,6 @@ func runBridgeRm(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Printf("Successfully removed bridge configuration %v\n", args[0])
+ env.out.Printf("Successfully removed bridge configuration %v\n", args[0])
return nil
}
-
-var bridgeRmCmd = &cobra.Command{
- Use: "rm <name>",
- Short: "Delete a configured bridge.",
- PreRunE: loadRepo,
- RunE: runBridgeRm,
- Args: cobra.ExactArgs(1),
-}
-
-func init() {
- bridgeCmd.AddCommand(bridgeRmCmd)
-}