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