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 PostRunE: closeBackend(env),
17 RunE: func(cmd *cobra.Command, args []string) error {
18 return runPush(env, args)
19 },
20 }
21
22 return cmd
23}
24
25func runPush(env *Env, args []string) error {
26 if len(args) > 1 {
27 return errors.New("Only pushing to one remote at a time is supported")
28 }
29
30 remote := "origin"
31 if len(args) == 1 {
32 remote = args[0]
33 }
34
35 stdout, err := env.backend.Push(remote)
36 if err != nil {
37 return err
38 }
39
40 env.out.Println(stdout)
41
42 return nil
43}