syft/internal/ui/logger_ui.go
Alex Goodman c5390264b0 split UI from event handling
Signed-off-by: Alex Goodman <wagoodman@gmail.com>
2021-06-26 23:32:28 -04:00

41 lines
839 B
Go

package ui
import (
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/internal/ui/common"
syftEvent "github.com/anchore/syft/syft/event"
"github.com/wagoodman/go-partybus"
)
type loggerUI struct {
unsubscribe func() error
}
func NewLoggerUI() UI {
return &loggerUI{}
}
func (l *loggerUI) Setup(unsubscribe func() error) error {
l.unsubscribe = unsubscribe
return nil
}
func (l loggerUI) Handle(event partybus.Event) error {
// ignore all events except for the final event
if event.Type != syftEvent.PresenterReady {
return nil
}
err := common.CatalogerPresenterReady(event)
if err != nil {
log.Errorf("unable to show catalog image finished event: %+v", err)
}
// this is the last expected event, stop listening to events
return l.unsubscribe()
}
func (l loggerUI) Teardown() error {
return nil
}