diff --git a/api/progress/noop.go b/api/progress/noop.go index e638b8725..46ec1290e 100644 --- a/api/progress/noop.go +++ b/api/progress/noop.go @@ -30,5 +30,8 @@ func (p *noopWriter) Start(ctx context.Context) error { func (p *noopWriter) Event(e Event) { } +func (p *noopWriter) TailMsgf(_ string, _ ...interface{}) { +} + func (p *noopWriter) Stop() { } diff --git a/api/progress/plain.go b/api/progress/plain.go index 75d4168d3..98e26abbd 100644 --- a/api/progress/plain.go +++ b/api/progress/plain.go @@ -40,6 +40,10 @@ func (p *plainWriter) Event(e Event) { fmt.Fprintln(p.out, e.ID, e.Text, e.StatusText) } +func (p *plainWriter) TailMsgf(m string, args ...interface{}) { + fmt.Fprintln(p.out, append([]interface{}{m}, args...)...) +} + func (p *plainWriter) Stop() { p.done <- true } diff --git a/api/progress/tty.go b/api/progress/tty.go index 36999cf88..0dd907a6d 100644 --- a/api/progress/tty.go +++ b/api/progress/tty.go @@ -32,13 +32,14 @@ import ( ) type ttyWriter struct { - out io.Writer - events map[string]Event - eventIDs []string - repeated bool - numLines int - done chan bool - mtx *sync.RWMutex + out io.Writer + events map[string]Event + eventIDs []string + repeated bool + numLines int + done chan bool + mtx *sync.RWMutex + tailEvents []string } func (w *ttyWriter) Start(ctx context.Context) error { @@ -48,9 +49,11 @@ func (w *ttyWriter) Start(ctx context.Context) error { select { case <-ctx.Done(): w.print() + w.printTailEvents() return ctx.Err() case <-w.done: w.print() + w.printTailEvents() return nil case <-ticker.C: w.print() @@ -91,6 +94,20 @@ func (w *ttyWriter) Event(e Event) { } } +func (w *ttyWriter) TailMsgf(msg string, args ...interface{}) { + w.mtx.Lock() + defer w.mtx.Unlock() + w.tailEvents = append(w.tailEvents, fmt.Sprintf(msg, args...)) +} + +func (w *ttyWriter) printTailEvents() { + w.mtx.Lock() + defer w.mtx.Unlock() + for _, msg := range w.tailEvents { + fmt.Fprintln(w.out, msg) + } +} + func (w *ttyWriter) print() { w.mtx.Lock() defer w.mtx.Unlock() diff --git a/api/progress/writer.go b/api/progress/writer.go index 656c125d3..7832366ad 100644 --- a/api/progress/writer.go +++ b/api/progress/writer.go @@ -31,6 +31,7 @@ type Writer interface { Start(context.Context) error Stop() Event(Event) + TailMsgf(string, ...interface{}) } type writerKey struct{} diff --git a/local/compose/pull.go b/local/compose/pull.go index 8a4f79257..1be445fc5 100644 --- a/local/compose/pull.go +++ b/local/compose/pull.go @@ -21,7 +21,6 @@ import ( "encoding/base64" "encoding/json" "errors" - "fmt" "io" "strings" @@ -72,13 +71,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts if !opts.IgnoreFailures { return err } - // If IgnoreFailures we still want to show the error message - w.Event(progress.Event{ - ID: fmt.Sprintf("Pulling %s:", service.Name), - Text: fmt.Sprintf("%v", err), - Status: progress.Error, - StatusText: fmt.Sprintf("%s", err), - }) + w.TailMsgf("Pulling %s: %s", service.Name, err.Error()) } return nil }) diff --git a/local/compose/push.go b/local/compose/push.go index ac0185f6e..a246753e5 100644 --- a/local/compose/push.go +++ b/local/compose/push.go @@ -70,12 +70,7 @@ func (s *composeService) Push(ctx context.Context, project *types.Project, optio if !options.IgnoreFailures { return err } - w.Event(progress.Event{ - ID: fmt.Sprintf("Pushing %s:", service.Name), - Text: fmt.Sprintf("%v", err), - Status: progress.Error, - StatusText: fmt.Sprintf("%s", err), - }) + w.TailMsgf("Pushing %s: %s", service.Name, err.Error()) } return nil })