mirror of https://github.com/docker/compose.git
Merge pull request #1467 from ulyssessouza/progress-tail-msgs
Add plain tail messages on progress writer
This commit is contained in:
commit
5b61e80e92
|
@ -30,5 +30,8 @@ func (p *noopWriter) Start(ctx context.Context) error {
|
||||||
func (p *noopWriter) Event(e Event) {
|
func (p *noopWriter) Event(e Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *noopWriter) TailMsgf(_ string, _ ...interface{}) {
|
||||||
|
}
|
||||||
|
|
||||||
func (p *noopWriter) Stop() {
|
func (p *noopWriter) Stop() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,10 @@ func (p *plainWriter) Event(e Event) {
|
||||||
fmt.Fprintln(p.out, e.ID, e.Text, e.StatusText)
|
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() {
|
func (p *plainWriter) Stop() {
|
||||||
p.done <- true
|
p.done <- true
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ttyWriter struct {
|
type ttyWriter struct {
|
||||||
out io.Writer
|
out io.Writer
|
||||||
events map[string]Event
|
events map[string]Event
|
||||||
eventIDs []string
|
eventIDs []string
|
||||||
repeated bool
|
repeated bool
|
||||||
numLines int
|
numLines int
|
||||||
done chan bool
|
done chan bool
|
||||||
mtx *sync.RWMutex
|
mtx *sync.RWMutex
|
||||||
|
tailEvents []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *ttyWriter) Start(ctx context.Context) error {
|
func (w *ttyWriter) Start(ctx context.Context) error {
|
||||||
|
@ -48,9 +49,11 @@ func (w *ttyWriter) Start(ctx context.Context) error {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
w.print()
|
w.print()
|
||||||
|
w.printTailEvents()
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
case <-w.done:
|
case <-w.done:
|
||||||
w.print()
|
w.print()
|
||||||
|
w.printTailEvents()
|
||||||
return nil
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
w.print()
|
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() {
|
func (w *ttyWriter) print() {
|
||||||
w.mtx.Lock()
|
w.mtx.Lock()
|
||||||
defer w.mtx.Unlock()
|
defer w.mtx.Unlock()
|
||||||
|
|
|
@ -31,6 +31,7 @@ type Writer interface {
|
||||||
Start(context.Context) error
|
Start(context.Context) error
|
||||||
Stop()
|
Stop()
|
||||||
Event(Event)
|
Event(Event)
|
||||||
|
TailMsgf(string, ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type writerKey struct{}
|
type writerKey struct{}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -72,13 +71,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts
|
||||||
if !opts.IgnoreFailures {
|
if !opts.IgnoreFailures {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If IgnoreFailures we still want to show the error message
|
w.TailMsgf("Pulling %s: %s", service.Name, err.Error())
|
||||||
w.Event(progress.Event{
|
|
||||||
ID: fmt.Sprintf("Pulling %s:", service.Name),
|
|
||||||
Text: fmt.Sprintf("%v", err),
|
|
||||||
Status: progress.Error,
|
|
||||||
StatusText: fmt.Sprintf("%s", err),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -70,12 +70,7 @@ func (s *composeService) Push(ctx context.Context, project *types.Project, optio
|
||||||
if !options.IgnoreFailures {
|
if !options.IgnoreFailures {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.Event(progress.Event{
|
w.TailMsgf("Pushing %s: %s", service.Name, err.Error())
|
||||||
ID: fmt.Sprintf("Pushing %s:", service.Name),
|
|
||||||
Text: fmt.Sprintf("%v", err),
|
|
||||||
Status: progress.Error,
|
|
||||||
StatusText: fmt.Sprintf("%s", err),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue