Introduce ergonomic API for handling multiple container events

Signed-off-by: Nikhil Benesch <nikhil.benesch@gmail.com>
This commit is contained in:
Nikhil Benesch 2022-01-07 13:01:59 -05:00 committed by Nicolas De loof
parent 5eb314a4ca
commit ee586e7f1e
5 changed files with 29 additions and 13 deletions

View file

@ -27,7 +27,10 @@ func (p *noopWriter) Start(ctx context.Context) error {
return nil
}
func (p *noopWriter) Event(e Event) {
func (p *noopWriter) Event(Event) {
}
func (p *noopWriter) Events([]Event) {
}
func (p *noopWriter) TailMsgf(_ string, _ ...interface{}) {

View file

@ -40,6 +40,12 @@ func (p *plainWriter) Event(e Event) {
fmt.Fprintln(p.out, e.ID, e.Text, e.StatusText)
}
func (p *plainWriter) Events(events []Event) {
for _, e := range events {
p.Event(e)
}
}
func (p *plainWriter) TailMsgf(m string, args ...interface{}) {
fmt.Fprintln(p.out, append([]interface{}{m}, args...)...)
}

View file

@ -95,6 +95,12 @@ func (w *ttyWriter) Event(e Event) {
}
}
func (w *ttyWriter) Events(events []Event) {
for _, e := range events {
w.Event(e)
}
}
func (w *ttyWriter) TailMsgf(msg string, args ...interface{}) {
w.mtx.Lock()
defer w.mtx.Unlock()

View file

@ -31,6 +31,7 @@ type Writer interface {
Start(context.Context) error
Stop()
Event(Event)
Events([]Event)
TailMsgf(string, ...interface{})
}