aboutsummaryrefslogtreecommitdiffstats
path: root/commands/push.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/push.go
parentc0dbc149d5c0c3610476ba14a800c9ba803a2c2c (diff)
downloadgit-bug-26bd1dd11010b4d86cebe2510ad7085a6b316334.tar.gz
commands: refactor to avoid globals
Diffstat (limited to 'commands/push.go')
-rw-r--r--commands/push.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/commands/push.go b/commands/push.go
index 8f67d3c0..fee8a50d 100644
--- a/commands/push.go
+++ b/commands/push.go
@@ -2,14 +2,29 @@ package commands
import (
"errors"
- "fmt"
+
+ "github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/util/interrupt"
- "github.com/spf13/cobra"
)
-func runPush(cmd *cobra.Command, args []string) error {
+func newPushCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "push [<remote>]",
+ Short: "Push bugs update to a git remote.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runPush(env, args)
+ },
+ }
+
+ return cmd
+}
+
+func runPush(env *Env, args []string) error {
if len(args) > 1 {
return errors.New("Only pushing to one remote at a time is supported")
}
@@ -19,7 +34,7 @@ func runPush(cmd *cobra.Command, args []string) error {
remote = args[0]
}
- backend, err := cache.NewRepoCache(repo)
+ backend, err := cache.NewRepoCache(env.repo)
if err != nil {
return err
}
@@ -31,19 +46,7 @@ func runPush(cmd *cobra.Command, args []string) error {
return err
}
- fmt.Println(stdout)
+ env.out.Println(stdout)
return nil
}
-
-// showCmd defines the "push" subcommand.
-var pushCmd = &cobra.Command{
- Use: "push [<remote>]",
- Short: "Push bugs update to a git remote.",
- PreRunE: loadRepo,
- RunE: runPush,
-}
-
-func init() {
- RootCmd.AddCommand(pushCmd)
-}