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(env *execenv.Env) *cobra.Command {
13 cmd := &cobra.Command{
14 Use: "push [REMOTE]",
15 Short: "Push updates to a git remote",
16 PreRunE: execenv.LoadBackend(env),
17 RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
18 return runPush(env, args)
19 }),
20 ValidArgsFunction: completion.GitRemote(env),
21 }
22
23 return cmd
24}
25
26func runPush(env *execenv.Env, args []string) error {
27 if len(args) > 1 {
28 return errors.New("Only pushing to one remote at a time is supported")
29 }
30
31 remote := "origin"
32 if len(args) == 1 {
33 remote = args[0]
34 }
35
36 stdout, err := env.Backend.Push(remote)
37 if err != nil {
38 return err
39 }
40
41 env.Out.Println(stdout)
42
43 return nil
44}