github.com/anchore/syft@v1.38.2/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.TaskProgress {
    40  	t := &monitor.TaskProgress{
    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  }
    53  
    54  func StartPullSourceTask(info monitor.GenericTask, size int64, initialStage string) *monitor.TaskProgress {
    55  	t := &monitor.TaskProgress{
    56  		AtomicStage: progress.NewAtomicStage(initialStage),
    57  		Manual:      progress.NewManual(size),
    58  	}
    59  
    60  	Publish(partybus.Event{
    61  		Type:   event.PullSourceStarted,
    62  		Source: info,
    63  		Value:  progress.StagedProgressable(t),
    64  	})
    65  
    66  	return t
    67  }
    68  
    69  func StartIndexingFiles(path string) *monitor.TaskProgress {
    70  	t := &monitor.TaskProgress{
    71  		AtomicStage: progress.NewAtomicStage(""),
    72  		Manual:      progress.NewManual(-1),
    73  	}
    74  
    75  	Publish(partybus.Event{
    76  		Type:   event.FileIndexingStarted,
    77  		Source: path,
    78  		Value:  progress.StagedProgressable(t),
    79  	})
    80  
    81  	return t
    82  }