1package commands
2
3import (
4 "fmt"
5 "time"
6
7 "github.com/spf13/cobra"
8
9 "github.com/MichaelMure/git-bug/bridge"
10 "github.com/MichaelMure/git-bug/bridge/core"
11 "github.com/MichaelMure/git-bug/cache"
12 "github.com/MichaelMure/git-bug/util/interrupt"
13)
14
15func runBridgePush(cmd *cobra.Command, args []string) error {
16 backend, err := cache.NewRepoCache(repo)
17 if err != nil {
18 return err
19 }
20 defer backend.Close()
21 interrupt.RegisterCleaner(backend.Close)
22
23 var b *core.Bridge
24
25 if len(args) == 0 {
26 b, err = bridge.DefaultBridge(backend)
27 } else {
28 b, err = bridge.LoadBridge(backend, args[0])
29 }
30
31 if err != nil {
32 return err
33 }
34
35 // TODO: by default export only new events
36 out, err := b.ExportAll(time.Time{})
37 if err != nil {
38 return err
39 }
40
41 for result := range out {
42 if result.Err != nil {
43 fmt.Println(result.Err, result.Reason)
44 } else {
45 fmt.Printf("%s: %s\n", result.String(), result.ID)
46 }
47 }
48
49 return nil
50}
51
52var bridgePushCmd = &cobra.Command{
53 Use: "push [<name>]",
54 Short: "Push updates.",
55 PreRunE: loadRepo,
56 RunE: runBridgePush,
57 Args: cobra.MaximumNArgs(1),
58}
59
60func init() {
61 bridgeCmd.AddCommand(bridgePushCmd)
62}