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