1package commands
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/cache"
8 "github.com/MichaelMure/git-bug/cleaner"
9 "github.com/spf13/cobra"
10)
11
12func runPush(cmd *cobra.Command, args []string) error {
13 if len(args) > 1 {
14 return errors.New("Only pushing to one remote at a time is supported")
15 }
16
17 remote := "origin"
18 if len(args) == 1 {
19 remote = args[0]
20 }
21
22 backend, err := cache.NewRepoCache(repo)
23 if err != nil {
24 return err
25 }
26 defer backend.Close()
27 cleaner.Register(backend.Close)
28
29 stdout, err := backend.Push(remote)
30 if err != nil {
31 return err
32 }
33
34 fmt.Println(stdout)
35
36 return nil
37}
38
39// showCmd defines the "push" subcommand.
40var pushCmd = &cobra.Command{
41 Use: "push [<remote>]",
42 Short: "Push bugs update to a git remote",
43 PreRunE: loadRepo,
44 RunE: runPush,
45}
46
47func init() {
48 RootCmd.AddCommand(pushCmd)
49}