From 26bd1dd11010b4d86cebe2510ad7085a6b316334 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 28 Jun 2020 18:26:29 +0200 Subject: commands: refactor to avoid globals --- commands/bridge_rm.go | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'commands/bridge_rm.go') 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 ", + 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 ", - Short: "Delete a configured bridge.", - PreRunE: loadRepo, - RunE: runBridgeRm, - Args: cobra.ExactArgs(1), -} - -func init() { - bridgeCmd.AddCommand(bridgeRmCmd) -} -- cgit