diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 83926e1..0b826d1 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -23,6 +23,9 @@ func (a App) Command() *cobra.Command { } cmd.SetOut(os.Stdout) cmd.SetErr(os.Stderr) + cmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) { + cmd.SilenceUsage = true + } opts := &cli.Options{} subs := []subcommand{ sync{opts}, diff --git a/internal/cmd/sync.go b/internal/cmd/sync.go index 2f7f27c..1e330a9 100644 --- a/internal/cmd/sync.go +++ b/internal/cmd/sync.go @@ -15,10 +15,10 @@ type sync struct { func (s sync) command() *cobra.Command { cmd := &cobra.Command{ - Use: "sync", + Use: "sync [project-dir]", Short: "Synchronize to the upstream releases", ValidArgs: []string{"REPOSITORY"}, - Args: cobra.OnlyValidArgs, + Args: cobra.MaximumNArgs(1), RunE: s.run, } return cmd @@ -35,6 +35,9 @@ func (s sync) project(args []string) func() config.Project { if err != nil { wd = "/" } + if len(args) > 0 { + wd = args[0] + } if !path.IsAbs(configPath) { configPath = path.Join(wd, configPath) } @@ -42,9 +45,6 @@ func (s sync) project(args []string) func() config.Project { ConfigPath: configPath, Path: wd, } - if len(args) > 0 { - project.Path = args[0] - } return project } } diff --git a/pkg/sync/create_pr.go b/pkg/sync/create_pr.go index 9dd9c7f..1f8625a 100644 --- a/pkg/sync/create_pr.go +++ b/pkg/sync/create_pr.go @@ -101,7 +101,7 @@ func (c createPR) open() error { cl := github.NewClient(args...) cl.ProjectDir = c.Path buff, err := cl.Execute(c.Context) - defer c.Println("Github client:", buff) + defer c.Println("Github client:", string(buff)) return errors.Wrap(err, ErrSyncFailed) } diff --git a/pkg/sync/mirror_release.go b/pkg/sync/mirror_release.go index 7065493..600aaec 100644 --- a/pkg/sync/mirror_release.go +++ b/pkg/sync/mirror_release.go @@ -74,14 +74,16 @@ func (r createNewRelease) checkoutAsNewRelease(upstreamBranch, downstreamBranch type push struct { state.State - branch string + branch string + skipDelete bool } func (p push) steps() []step { - return []step{ - p.push, - p.delete, + st := []step{p.push} + if !p.skipDelete { + st = append(st, p.delete) } + return st } func (p push) push() error { diff --git a/pkg/sync/resync_releases.go b/pkg/sync/resync_releases.go index fbc2f28..84adcc4 100644 --- a/pkg/sync/resync_releases.go +++ b/pkg/sync/resync_releases.go @@ -88,7 +88,7 @@ func (r resyncRelease) run() error { return nil } err = multiStep{ - r.pushBranch(syncBranch), + r.pushBranch(syncBranch, skipDeleteOnPush), r.createSyncReleasePR(downstreamBranch, upstreamBranch, syncBranch), }.runSteps() return diff --git a/pkg/sync/sync_release_next.go b/pkg/sync/sync_release_next.go index 54e024a..a62d446 100644 --- a/pkg/sync/sync_release_next.go +++ b/pkg/sync/sync_release_next.go @@ -9,12 +9,21 @@ func (o Operation) syncReleaseNext() error { }) } -func (o Operation) pushBranch(branch string) step { +type pushOpt func(*push) + +func skipDeleteOnPush(p *push) { + p.skipDelete = true +} + +func (o Operation) pushBranch(branch string, opts ...pushOpt) step { return func() error { p := push{ State: o.State, branch: branch, } + for _, opt := range opts { + opt(&p) + } return runSteps(p.steps()) } }