1package commands
2
3import (
4 "errors"
5
6 "github.com/spf13/cobra"
7)
8
9func newPushCommand() *cobra.Command {
10 env := newEnv()
11
12 cmd := &cobra.Command{
13 Use: "push [REMOTE]",
14 Short: "Push bugs update to a git remote.",
15 PreRunE: loadBackend(env),
16 RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
17 return runPush(env, args)
18 }),
19 }
20
21 return cmd
22}
23
24func runPush(env *Env, args []string) error {
25 if len(args) > 1 {
26 return errors.New("Only pushing to one remote at a time is supported")
27 }
28
29 remote := "origin"
30 if len(args) == 1 {
31 remote = args[0]
32 }
33
34 stdout, err := env.backend.Push(remote)
35 if err != nil {
36 return err
37 }
38
39 env.out.Println(stdout)
40
41 return nil
42}