mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 23:16:30 +01:00
allow root command to catalog a directory
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
+30
-28
@@ -17,13 +17,14 @@ import (
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: fmt.Sprintf("%s [IMAGE]", internal.ApplicationName),
|
||||
Short: "A container image BOM tool", // TODO: add copy
|
||||
Use: fmt.Sprintf("%s [SOURCE]", internal.ApplicationName),
|
||||
Short: "A tool that generates a Software Build Of Materials (SBOM)",
|
||||
Long: internal.Tprintf(`\
|
||||
Supports the following image sources:
|
||||
{{.appName}} yourrepo/yourimage:tag defaults to using images from a docker daemon
|
||||
{{.appName}} docker://yourrepo/yourimage:tag explicitly use the docker daemon
|
||||
{{.appName}} tar://path/to/yourimage.tar use a tarball from disk
|
||||
{{.appName}} tar://path/to/yourimage.tar use a tarball from disk
|
||||
{{.appName}} dir://path/to/yourproject read directly from a path in disk
|
||||
`, map[string]interface{}{
|
||||
"appName": internal.ApplicationName,
|
||||
}),
|
||||
@@ -44,38 +45,38 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func startWorker(userImage string) <-chan error {
|
||||
func startWorker(userInput string) <-chan error {
|
||||
errs := make(chan error)
|
||||
go func() {
|
||||
defer close(errs)
|
||||
|
||||
log.Infof("Fetching image '%s'", userImage)
|
||||
img, err := stereoscope.GetImage(userImage)
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("could not fetch image '%s': %w", userImage, err)
|
||||
return
|
||||
}
|
||||
defer stereoscope.Cleanup()
|
||||
|
||||
log.Info("Identifying Distro")
|
||||
distro := imgbom.IdentifyDistro(img)
|
||||
if distro == nil {
|
||||
log.Errorf("error identifying distro")
|
||||
} else {
|
||||
log.Infof(" Distro: %s", distro)
|
||||
}
|
||||
|
||||
log.Info("Cataloging image")
|
||||
catalog, err := imgbom.CatalogImage(img, appConfig.ScopeOpt)
|
||||
protocol := imgbom.NewProtocol(userInput)
|
||||
fmt.Printf("protocol: %+v", protocol)
|
||||
catalog, err := imgbom.Catalog(protocol, appConfig.ScopeOpt)
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("could not catalog image: %w", err)
|
||||
}
|
||||
|
||||
log.Info("Complete!")
|
||||
bus.Publish(partybus.Event{
|
||||
Type: event.CatalogerFinished,
|
||||
Value: presenter.GetPresenter(appConfig.PresenterOpt, img, catalog),
|
||||
})
|
||||
switch protocol.Type {
|
||||
case imgbom.DirProtocol:
|
||||
log.Info("Cataloging directory")
|
||||
bus.Publish(partybus.Event{
|
||||
Type: event.CatalogerFinished,
|
||||
Value: presenter.GetDirPresenter(appConfig.PresenterOpt, catalog),
|
||||
})
|
||||
default:
|
||||
log.Info("Cataloging image")
|
||||
log.Infof("Fetching image '%s'", userInput)
|
||||
img, err := stereoscope.GetImage(userInput)
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("could not fetch image '%s': %w", userInput, err)
|
||||
}
|
||||
defer stereoscope.Cleanup()
|
||||
|
||||
bus.Publish(partybus.Event{
|
||||
Type: event.CatalogerFinished,
|
||||
Value: presenter.GetImgPresenter(appConfig.PresenterOpt, img, catalog),
|
||||
})
|
||||
}
|
||||
}()
|
||||
return errs
|
||||
}
|
||||
@@ -86,4 +87,5 @@ func doRunCmd(_ *cobra.Command, args []string) int {
|
||||
ux := ui.Select(appConfig.CliOptions.Verbosity > 0, appConfig.Quiet)
|
||||
|
||||
return ux(errs, eventSubscription)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user