diff options
Diffstat (limited to 'commands/bridge_push.go')
-rw-r--r-- | commands/bridge_push.go | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/commands/bridge_push.go b/commands/bridge_push.go index 52d23a97..73df87fb 100644 --- a/commands/bridge_push.go +++ b/commands/bridge_push.go @@ -2,7 +2,6 @@ package commands import ( "context" - "fmt" "os" "sync" "time" @@ -15,8 +14,24 @@ import ( "github.com/MichaelMure/git-bug/util/interrupt" ) -func runBridgePush(cmd *cobra.Command, args []string) error { - backend, err := cache.NewRepoCache(repo) +func newBridgePushCommand() *cobra.Command { + env := newEnv() + + cmd := &cobra.Command{ + Use: "push [<name>]", + Short: "Push updates.", + PreRunE: loadRepoEnsureUser(env), + RunE: func(cmd *cobra.Command, args []string) error { + return runBridgePush(env, args) + }, + Args: cobra.MaximumNArgs(1), + } + + return cmd +} + +func runBridgePush(env *Env, args []string) error { + backend, err := cache.NewRepoCache(env.repo) if err != nil { return err } @@ -46,14 +61,14 @@ func runBridgePush(cmd *cobra.Command, args []string) error { interrupt.RegisterCleaner(func() error { mu.Lock() if interruptCount > 0 { - fmt.Println("Received another interrupt before graceful stop, terminating...") + env.err.Println("Received another interrupt before graceful stop, terminating...") os.Exit(0) } interruptCount++ mu.Unlock() - fmt.Println("Received interrupt signal, stopping the import...\n(Hit ctrl-c again to kill the process.)") + env.err.Println("Received interrupt signal, stopping the import...\n(Hit ctrl-c again to kill the process.)") // send signal to stop the importer cancel() @@ -71,7 +86,7 @@ func runBridgePush(cmd *cobra.Command, args []string) error { exportedIssues := 0 for result := range events { if result.Event != core.ExportEventNothing { - fmt.Println(result.String()) + env.out.Println(result.String()) } switch result.Event { @@ -80,21 +95,9 @@ func runBridgePush(cmd *cobra.Command, args []string) error { } } - fmt.Printf("exported %d issues with %s bridge\n", exportedIssues, b.Name) + env.out.Printf("exported %d issues with %s bridge\n", exportedIssues, b.Name) // send done signal close(done) return nil } - -var bridgePushCmd = &cobra.Command{ - Use: "push [<name>]", - Short: "Push updates.", - PreRunE: loadRepoEnsureUser, - RunE: runBridgePush, - Args: cobra.MaximumNArgs(1), -} - -func init() { - bridgeCmd.AddCommand(bridgePushCmd) -} |