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