aboutsummaryrefslogtreecommitdiffstats
path: root/commands/pull.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/pull.go')
-rw-r--r--commands/pull.go42
1 files changed, 22 insertions, 20 deletions
diff --git a/commands/pull.go b/commands/pull.go
index 0439ab41..fb50a03b 100644
--- a/commands/pull.go
+++ b/commands/pull.go
@@ -2,7 +2,6 @@ package commands
import (
"errors"
- "fmt"
"github.com/spf13/cobra"
@@ -11,7 +10,22 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
-func runPull(cmd *cobra.Command, args []string) error {
+func newPullCommand() *cobra.Command {
+ env := newEnv()
+
+ cmd := &cobra.Command{
+ Use: "pull [<remote>]",
+ Short: "Pull bugs update from a git remote.",
+ PreRunE: loadRepo(env),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return runPull(env, args)
+ },
+ }
+
+ return cmd
+}
+
+func runPull(env *Env, args []string) error {
if len(args) > 1 {
return errors.New("Only pulling from one remote at a time is supported")
}
@@ -21,45 +35,33 @@ func runPull(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
}
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
- fmt.Println("Fetching remote ...")
+ env.out.Println("Fetching remote ...")
stdout, err := backend.Fetch(remote)
if err != nil {
return err
}
- fmt.Println(stdout)
+ env.out.Println(stdout)
- fmt.Println("Merging data ...")
+ env.out.Println("Merging data ...")
for result := range backend.MergeAll(remote) {
if result.Err != nil {
- fmt.Println(result.Err)
+ env.err.Println(result.Err)
}
if result.Status != entity.MergeStatusNothing {
- fmt.Printf("%s: %s\n", result.Id.Human(), result)
+ env.out.Printf("%s: %s\n", result.Id.Human(), result)
}
}
return nil
}
-
-// showCmd defines the "push" subcommand.
-var pullCmd = &cobra.Command{
- Use: "pull [<remote>]",
- Short: "Pull bugs update from a git remote.",
- PreRunE: loadRepo,
- RunE: runPull,
-}
-
-func init() {
- RootCmd.AddCommand(pullCmd)
-}