Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit e5834f3

Browse files
committed
Add tail messages on progress writer
Signed-off-by: Ulysses Souza <[email protected]>
1 parent ee4e85a commit e5834f3

File tree

6 files changed

+34
-21
lines changed

6 files changed

+34
-21
lines changed

api/progress/noop.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ func (p *noopWriter) Start(ctx context.Context) error {
3030
func (p *noopWriter) Event(e Event) {
3131
}
3232

33+
func (p *noopWriter) TailMsgf(_ string, _ ...interface{}) {
34+
}
35+
3336
func (p *noopWriter) Stop() {
3437
}

api/progress/plain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func (p *plainWriter) Event(e Event) {
4040
fmt.Fprintln(p.out, e.ID, e.Text, e.StatusText)
4141
}
4242

43+
func (p *plainWriter) TailMsgf(m string, args ...interface{}) {
44+
fmt.Fprintln(p.out, append([]interface{}{m}, args...)...)
45+
}
46+
4347
func (p *plainWriter) Stop() {
4448
p.done <- true
4549
}

api/progress/tty.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ import (
3232
)
3333

3434
type ttyWriter struct {
35-
out io.Writer
36-
events map[string]Event
37-
eventIDs []string
38-
repeated bool
39-
numLines int
40-
done chan bool
41-
mtx *sync.RWMutex
35+
out io.Writer
36+
events map[string]Event
37+
eventIDs []string
38+
repeated bool
39+
numLines int
40+
done chan bool
41+
mtx *sync.RWMutex
42+
tailEvents []string
4243
}
4344

4445
func (w *ttyWriter) Start(ctx context.Context) error {
@@ -48,9 +49,11 @@ func (w *ttyWriter) Start(ctx context.Context) error {
4849
select {
4950
case <-ctx.Done():
5051
w.print()
52+
w.printTailEvents()
5153
return ctx.Err()
5254
case <-w.done:
5355
w.print()
56+
w.printTailEvents()
5457
return nil
5558
case <-ticker.C:
5659
w.print()
@@ -91,6 +94,20 @@ func (w *ttyWriter) Event(e Event) {
9194
}
9295
}
9396

97+
func (w *ttyWriter) TailMsgf(msg string, args ...interface{}) {
98+
w.mtx.Lock()
99+
defer w.mtx.Unlock()
100+
w.tailEvents = append(w.tailEvents, fmt.Sprintf(msg, args...))
101+
}
102+
103+
func (w *ttyWriter) printTailEvents() {
104+
w.mtx.Lock()
105+
defer w.mtx.Unlock()
106+
for _, msg := range w.tailEvents {
107+
fmt.Fprintln(w.out, msg)
108+
}
109+
}
110+
94111
func (w *ttyWriter) print() {
95112
w.mtx.Lock()
96113
defer w.mtx.Unlock()

api/progress/writer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Writer interface {
3131
Start(context.Context) error
3232
Stop()
3333
Event(Event)
34+
TailMsgf(string, ...interface{})
3435
}
3536

3637
type writerKey struct{}

local/compose/pull.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/base64"
2222
"encoding/json"
2323
"errors"
24-
"fmt"
2524
"io"
2625
"strings"
2726

@@ -72,13 +71,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts
7271
if !opts.IgnoreFailures {
7372
return err
7473
}
75-
// If IgnoreFailures we still want to show the error message
76-
w.Event(progress.Event{
77-
ID: fmt.Sprintf("Pulling %s:", service.Name),
78-
Text: fmt.Sprintf("%v", err),
79-
Status: progress.Error,
80-
StatusText: fmt.Sprintf("%s", err),
81-
})
74+
w.TailMsgf("Pulling %s: %s", service.Name, err.Error())
8275
}
8376
return nil
8477
})

local/compose/push.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ func (s *composeService) Push(ctx context.Context, project *types.Project, optio
7070
if !options.IgnoreFailures {
7171
return err
7272
}
73-
w.Event(progress.Event{
74-
ID: fmt.Sprintf("Pushing %s:", service.Name),
75-
Text: fmt.Sprintf("%v", err),
76-
Status: progress.Error,
77-
StatusText: fmt.Sprintf("%s", err),
78-
})
73+
w.TailMsgf("Pushing %s: %s", service.Name, err.Error())
7974
}
8075
return nil
8176
})

0 commit comments

Comments
 (0)