github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/internal/bus/helpers.go (about)

     1  package bus
     2  
     3  import (
     4  	"github.com/wagoodman/go-partybus"
     5  	"github.com/wagoodman/go-progress"
     6  
     7  	"github.com/anchore/clio"
     8  	"github.com/anchore/syft/internal/redact"
     9  	"github.com/anchore/syft/syft/event"
    10  	"github.com/anchore/syft/syft/event/monitor"
    11  )
    12  
    13  func Exit() {
    14  	Publish(clio.ExitEvent(false))
    15  }
    16  
    17  func ExitWithInterrupt() {
    18  	Publish(clio.ExitEvent(true))
    19  }
    20  
    21  func Report(report string) {
    22  	if len(report) == 0 {
    23  		return
    24  	}
    25  	report = redact.Apply(report)
    26  	Publish(partybus.Event{
    27  		Type:  event.CLIReport,
    28  		Value: report,
    29  	})
    30  }
    31  
    32  func Notify(message string) {
    33  	Publish(partybus.Event{
    34  		Type:  event.CLINotification,
    35  		Value: message,
    36  	})
    37  }
    38  
    39  func StartCatalogerTask(info monitor.GenericTask, size int64, initialStage string) *monitor.CatalogerTaskProgress {
    40  	t := &monitor.CatalogerTaskProgress{
    41  		AtomicStage: progress.NewAtomicStage(initialStage),
    42  		Manual:      progress.NewManual(size),
    43  	}
    44  
    45  	Publish(partybus.Event{
    46  		Type:   event.CatalogerTaskStarted,
    47  		Source: info,
    48  		Value:  progress.StagedProgressable(t),
    49  	})
    50  
    51  	return t
    52  }