github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/cmd/syft/internal/ui/no_ui.go (about) 1 package ui 2 3 import ( 4 "io" 5 "os" 6 7 "github.com/wagoodman/go-partybus" 8 9 "github.com/anchore/clio" 10 "github.com/anchore/syft/syft/event" 11 ) 12 13 var _ clio.UI = (*NoUI)(nil) 14 15 type NoUI struct { 16 out io.Writer 17 err io.Writer 18 finalizeEvents []partybus.Event 19 subscription partybus.Unsubscribable 20 quiet bool 21 } 22 23 func None(out io.Writer, quiet bool) *NoUI { 24 return &NoUI{ 25 out: out, 26 err: os.Stderr, 27 quiet: quiet, 28 } 29 } 30 31 func (n *NoUI) Setup(subscription partybus.Unsubscribable) error { 32 n.subscription = subscription 33 return nil 34 } 35 36 func (n *NoUI) Handle(e partybus.Event) error { 37 switch e.Type { 38 case event.CLIReport, event.CLINotification: 39 // keep these for when the UI is terminated to show to the screen (or perform other events) 40 n.finalizeEvents = append(n.finalizeEvents, e) 41 } 42 return nil 43 } 44 45 func (n NoUI) Teardown(_ bool) error { 46 return writeEvents(n.out, n.err, n.quiet, n.finalizeEvents...) 47 }