mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
Signed-off-by: Keith Zantow <kzantow@gmail.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
43 lines
859 B
Go
43 lines
859 B
Go
package ui
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/wagoodman/go-partybus"
|
|
|
|
"github.com/anchore/clio"
|
|
"github.com/anchore/syft/syft/event"
|
|
)
|
|
|
|
var _ clio.UI = (*NoUI)(nil)
|
|
|
|
type NoUI struct {
|
|
finalizeEvents []partybus.Event
|
|
subscription partybus.Unsubscribable
|
|
quiet bool
|
|
}
|
|
|
|
func None(quiet bool) *NoUI {
|
|
return &NoUI{
|
|
quiet: quiet,
|
|
}
|
|
}
|
|
|
|
func (n *NoUI) Setup(subscription partybus.Unsubscribable) error {
|
|
n.subscription = subscription
|
|
return nil
|
|
}
|
|
|
|
func (n *NoUI) Handle(e partybus.Event) error {
|
|
switch e.Type {
|
|
case event.CLIReport, event.CLINotification:
|
|
// keep these for when the UI is terminated to show to the screen (or perform other events)
|
|
n.finalizeEvents = append(n.finalizeEvents, e)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (n NoUI) Teardown(_ bool) error {
|
|
return newPostUIEventWriter(os.Stdout, os.Stderr).write(n.quiet, n.finalizeEvents...)
|
|
}
|