cmd: do not default for images, handle it specifically

Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
Alfredo Deza
2020-07-15 09:59:40 -04:00
parent 2f626bf9fd
commit a6e1866cdb
2 changed files with 38 additions and 63 deletions
+12 -37
View File
@@ -7,12 +7,10 @@ import (
"github.com/anchore/imgbom/imgbom"
"github.com/anchore/imgbom/imgbom/event"
"github.com/anchore/imgbom/imgbom/presenter"
"github.com/anchore/imgbom/imgbom/scope"
"github.com/anchore/imgbom/internal"
"github.com/anchore/imgbom/internal/bus"
"github.com/anchore/imgbom/internal/log"
"github.com/anchore/imgbom/internal/ui"
"github.com/anchore/stereoscope"
"github.com/spf13/cobra"
"github.com/wagoodman/go-partybus"
)
@@ -50,54 +48,31 @@ func startWorker(userInput string) <-chan error {
errs := make(chan error)
go func() {
defer close(errs)
protocol := imgbom.NewProtocol(userInput)
log.Debugf("protocol: %+v", protocol)
var s scope.Scope
var err error
s, cleanup, err := imgbom.NewScope(userInput, appConfig.ScopeOpt)
defer cleanup()
switch protocol.Type {
case imgbom.DirProtocol:
// populate the scope object for dir
s, err = imgbom.GetScopeFromDir(protocol.Value, appConfig.ScopeOpt)
if err != nil {
errs <- fmt.Errorf("could not populate scope from path (%s): %w", protocol.Value, err)
}
default:
log.Infof("Fetching image '%s'", userInput)
img, err := stereoscope.GetImage(userInput)
if err != nil || img == nil {
errs <- fmt.Errorf("could not fetch image '%s': %w", userInput, err)
// TODO: this needs to be handled better
bus.Publish(partybus.Event{
Type: event.CatalogerFinished,
Value: nil,
})
return
}
defer stereoscope.Cleanup()
// populate the scope object for image
s, err = imgbom.GetScopeFromImage(img, appConfig.ScopeOpt)
if err != nil {
errs <- fmt.Errorf("could not populate scope with image: %w", err)
}
if err != nil {
log.Errorf("could not produce catalog: %w", err)
}
log.Info("Identifying Distro")
distro := imgbom.IdentifyDistro(s)
if distro == nil {
log.Errorf("error identifying distro")
} else {
log.Infof(" Distro: %s", distro)
}
log.Info("Creating the Catalog")
catalog, err := imgbom.Catalog(s)
if err != nil {
log.Errorf("could not produce catalog: %w", err)
}
bus.Publish(partybus.Event{
Type: event.CatalogerFinished,
Value: presenter.GetPresenter(appConfig.PresenterOpt, s),
Value: presenter.GetPresenter(appConfig.PresenterOpt, s, catalog),
})
}()
return errs