diff --git a/pkg/compose/build.go b/pkg/compose/build.go index 900eb7971..c5f1ffaee 100644 --- a/pkg/compose/build.go +++ b/pkg/compose/build.go @@ -47,10 +47,10 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti if err != nil { return err } - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { _, err := s.build(ctx, project, options) return err - }, s.stderr()) + }, s.stderr(), "Building") } //nolint:gocyclo diff --git a/pkg/compose/cp.go b/pkg/compose/cp.go index 802e851ee..3f4358462 100644 --- a/pkg/compose/cp.go +++ b/pkg/compose/cp.go @@ -44,9 +44,9 @@ const ( ) func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error { - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.copy(ctx, projectName, options) - }, s.stderr()) + }, s.stderr(), "Copying") } func (s *composeService) copy(ctx context.Context, projectName string, options api.CopyOptions) error { diff --git a/pkg/compose/create.go b/pkg/compose/create.go index 0047b30a9..854387289 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -49,9 +49,9 @@ import ( ) func (s *composeService) Create(ctx context.Context, project *types.Project, options api.CreateOptions) error { - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.create(ctx, project, options) - }, s.stderr()) + }, s.stderr(), "Creating") } func (s *composeService) create(ctx context.Context, project *types.Project, options api.CreateOptions) error { diff --git a/pkg/compose/kill.go b/pkg/compose/kill.go index 7a9aa43f7..b7a1faf16 100644 --- a/pkg/compose/kill.go +++ b/pkg/compose/kill.go @@ -29,9 +29,9 @@ import ( ) func (s *composeService) Kill(ctx context.Context, projectName string, options api.KillOptions) error { - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.kill(ctx, strings.ToLower(projectName), options) - }, s.stderr()) + }, s.stderr(), "Killing") } func (s *composeService) kill(ctx context.Context, projectName string, options api.KillOptions) error { diff --git a/pkg/compose/pause.go b/pkg/compose/pause.go index d094fc8af..cc303da12 100644 --- a/pkg/compose/pause.go +++ b/pkg/compose/pause.go @@ -28,9 +28,9 @@ import ( ) func (s *composeService) Pause(ctx context.Context, projectName string, options api.PauseOptions) error { - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.pause(ctx, strings.ToLower(projectName), options) - }, s.stderr()) + }, s.stderr(), "Pausing") } func (s *composeService) pause(ctx context.Context, projectName string, options api.PauseOptions) error { diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index dfb6069a0..5dcd2a63e 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -42,9 +42,9 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, optio if options.Quiet { return s.pull(ctx, project, options) } - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.pull(ctx, project, options) - }, s.stderr()) + }, s.stderr(), "Pulling") } func (s *composeService) pull(ctx context.Context, project *types.Project, opts api.PullOptions) error { //nolint:gocyclo diff --git a/pkg/compose/push.go b/pkg/compose/push.go index 5e7446ef1..cc520edb0 100644 --- a/pkg/compose/push.go +++ b/pkg/compose/push.go @@ -40,9 +40,9 @@ func (s *composeService) Push(ctx context.Context, project *types.Project, optio if options.Quiet { return s.push(ctx, project, options) } - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.push(ctx, project, options) - }, s.stderr()) + }, s.stderr(), "Pushing") } func (s *composeService) push(ctx context.Context, project *types.Project, options api.PushOptions) error { diff --git a/pkg/compose/remove.go b/pkg/compose/remove.go index 45d8cbd71..b5804d5c8 100644 --- a/pkg/compose/remove.go +++ b/pkg/compose/remove.go @@ -93,9 +93,9 @@ func (s *composeService) Remove(ctx context.Context, projectName string, options return nil } } - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.remove(ctx, stoppedContainers, options) - }, s.stderr()) + }, s.stderr(), "Removing") } func (s *composeService) remove(ctx context.Context, containers Containers, options api.RemoveOptions) error { diff --git a/pkg/compose/restart.go b/pkg/compose/restart.go index c1f4ee741..8a3b9c259 100644 --- a/pkg/compose/restart.go +++ b/pkg/compose/restart.go @@ -29,9 +29,9 @@ import ( ) func (s *composeService) Restart(ctx context.Context, projectName string, options api.RestartOptions) error { - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.restart(ctx, strings.ToLower(projectName), options) - }, s.stderr()) + }, s.stderr(), "Restarting") } func (s *composeService) restart(ctx context.Context, projectName string, options api.RestartOptions) error { diff --git a/pkg/compose/stop.go b/pkg/compose/stop.go index 7c54d19d3..07d70502b 100644 --- a/pkg/compose/stop.go +++ b/pkg/compose/stop.go @@ -26,9 +26,9 @@ import ( ) func (s *composeService) Stop(ctx context.Context, projectName string, options api.StopOptions) error { - return progress.Run(ctx, func(ctx context.Context) error { + return progress.RunWithTitle(ctx, func(ctx context.Context) error { return s.stop(ctx, strings.ToLower(projectName), options) - }, s.stderr()) + }, s.stderr(), "Stopping") } func (s *composeService) stop(ctx context.Context, projectName string, options api.StopOptions) error { diff --git a/pkg/progress/tty.go b/pkg/progress/tty.go index 36c7653f9..77ef455de 100644 --- a/pkg/progress/tty.go +++ b/pkg/progress/tty.go @@ -43,6 +43,7 @@ type ttyWriter struct { tailEvents []string dryRun bool skipChildEvents bool + progressTitle string } func (w *ttyWriter) Start(ctx context.Context) error { @@ -149,7 +150,7 @@ func (w *ttyWriter) print() { //nolint:gocyclo fmt.Fprint(w.out, aec.Hide) defer fmt.Fprint(w.out, aec.Show) - firstLine := fmt.Sprintf("[+] Running %d/%d", numDone(w.events), w.numLines) + firstLine := fmt.Sprintf("[+] %s %d/%d", w.progressTitle, numDone(w.events), w.numLines) if w.numLines != 0 && numDone(w.events) == w.numLines { firstLine = DoneColor(firstLine) } diff --git a/pkg/progress/writer.go b/pkg/progress/writer.go index 67c2cbcd8..d2d18fe2e 100644 --- a/pkg/progress/writer.go +++ b/pkg/progress/writer.go @@ -61,14 +61,21 @@ type progressFuncWithStatus func(context.Context) (string, error) func Run(ctx context.Context, pf progressFunc, out io.Writer) error { _, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) { return "", pf(ctx) - }, out) + }, out, "Running") + return err +} + +func RunWithTitle(ctx context.Context, pf progressFunc, out io.Writer, progressTitle string) error { + _, err := RunWithStatus(ctx, func(ctx context.Context) (string, error) { + return "", pf(ctx) + }, out, progressTitle) return err } // RunWithStatus will run a writer and the progress function in parallel and return a status -func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer) (string, error) { +func RunWithStatus(ctx context.Context, pf progressFuncWithStatus, out io.Writer, progressTitle string) (string, error) { eg, _ := errgroup.WithContext(ctx) - w, err := NewWriter(ctx, out) + w, err := NewWriter(ctx, out, progressTitle) var result string if err != nil { return "", err @@ -105,17 +112,17 @@ const ( var Mode = ModeAuto // NewWriter returns a new multi-progress writer -func NewWriter(ctx context.Context, out io.Writer) (Writer, error) { +func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer, error) { _, isTerminal := term.GetFdInfo(out) dryRun, ok := ctx.Value(api.DryRunKey{}).(bool) if !ok { dryRun = false } if Mode == ModeAuto && isTerminal { - return newTTYWriter(out.(console.File), dryRun) + return newTTYWriter(out.(console.File), dryRun, progressTitle) } if Mode == ModeTTY { - return newTTYWriter(out.(console.File), dryRun) + return newTTYWriter(out.(console.File), dryRun, progressTitle) } return &plainWriter{ out: out, @@ -124,19 +131,20 @@ func NewWriter(ctx context.Context, out io.Writer) (Writer, error) { }, nil } -func newTTYWriter(out console.File, dryRun bool) (Writer, error) { +func newTTYWriter(out console.File, dryRun bool, progressTitle string) (Writer, error) { con, err := console.ConsoleFromFile(out) if err != nil { return nil, err } return &ttyWriter{ - out: con, - eventIDs: []string{}, - events: map[string]Event{}, - repeated: false, - done: make(chan bool), - mtx: &sync.Mutex{}, - dryRun: dryRun, + out: con, + eventIDs: []string{}, + events: map[string]Event{}, + repeated: false, + done: make(chan bool), + mtx: &sync.Mutex{}, + dryRun: dryRun, + progressTitle: progressTitle, }, nil }