2018-09-24 18:11:50 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-05-03 01:02:50 +03:00
|
|
|
"time"
|
|
|
|
|
2019-06-09 00:14:35 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2018-09-24 18:11:50 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bridge"
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core"
|
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2018-10-25 00:36:39 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
2018-09-24 18:11:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func runBridgePull(cmd *cobra.Command, args []string) error {
|
|
|
|
backend, err := cache.NewRepoCache(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer backend.Close()
|
2018-10-25 00:36:39 +03:00
|
|
|
interrupt.RegisterCleaner(backend.Close)
|
2018-09-24 18:11:50 +03:00
|
|
|
|
|
|
|
var b *core.Bridge
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
b, err = bridge.DefaultBridge(backend)
|
|
|
|
} else {
|
2019-06-15 03:33:06 +03:00
|
|
|
b, err = bridge.LoadBridge(backend, args[0])
|
2018-09-24 18:11:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-03 01:02:50 +03:00
|
|
|
// TODO: by default import only new events
|
|
|
|
err = b.ImportAll(time.Time{})
|
2018-09-24 18:11:50 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var bridgePullCmd = &cobra.Command{
|
2018-10-17 21:38:10 +03:00
|
|
|
Use: "pull [<name>]",
|
2019-02-24 16:46:08 +03:00
|
|
|
Short: "Pull updates.",
|
2018-10-17 21:38:10 +03:00
|
|
|
PreRunE: loadRepo,
|
|
|
|
RunE: runBridgePull,
|
2019-06-09 00:14:35 +03:00
|
|
|
Args: cobra.MaximumNArgs(1),
|
2018-09-24 18:11:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
bridgeCmd.AddCommand(bridgePullCmd)
|
|
|
|
}
|