mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* add output to file option Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * log errors on close of the report destination Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove file option from persistent args Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update file option comments and logging Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * allow for multiple UI fallback options Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update UI select signatures + tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
45 lines
1014 B
Go
45 lines
1014 B
Go
package ui
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/anchore/syft/internal/log"
|
|
syftEvent "github.com/anchore/syft/syft/event"
|
|
"github.com/wagoodman/go-partybus"
|
|
)
|
|
|
|
type loggerUI struct {
|
|
unsubscribe func() error
|
|
reportOutput io.Writer
|
|
}
|
|
|
|
// NewLoggerUI writes all events to the common application logger and writes the final report to the given writer.
|
|
func NewLoggerUI(reportWriter io.Writer) UI {
|
|
return &loggerUI{
|
|
reportOutput: reportWriter,
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
if err := handleCatalogerPresenterReady(event, l.reportOutput); err != nil {
|
|
log.Warnf("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(_ bool) error {
|
|
return nil
|
|
}
|