presenter: use new scoped source

Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
Alfredo Deza 2020-07-09 14:07:03 -04:00
parent 4b69758f2c
commit 6e9171e8a6

View File

@ -8,30 +8,50 @@ import (
json_imgs "github.com/anchore/imgbom/imgbom/presenter/json/imgs" json_imgs "github.com/anchore/imgbom/imgbom/presenter/json/imgs"
text_dirs "github.com/anchore/imgbom/imgbom/presenter/text/dirs" text_dirs "github.com/anchore/imgbom/imgbom/presenter/text/dirs"
text_imgs "github.com/anchore/imgbom/imgbom/presenter/text/imgs" text_imgs "github.com/anchore/imgbom/imgbom/presenter/text/imgs"
"github.com/anchore/stereoscope/pkg/image" "github.com/anchore/imgbom/imgbom/scope"
) )
type Presenter interface { type Presenter interface {
Present(io.Writer) error Present(io.Writer) error
} }
func GetImgPresenter(option Option, img *image.Image, catalog *pkg.Catalog) Presenter { // GetPresenter returns a presenter for images or directories
switch option { func GetPresenter(option Option, s scope.Scope, catalog *pkg.Catalog) Presenter {
case JSONPresenter: src := s.Source()
return json_imgs.NewPresenter(img, catalog)
case TextPresenter: switch src.(type) {
return text_imgs.NewPresenter(img, catalog) case scope.DirSource:
return GetDirPresenter(option, s, catalog)
case scope.ImageSource:
return GetImgPresenter(option, s, catalog)
default: default:
return nil return nil
} }
} }
func GetDirPresenter(option Option, path string, catalog *pkg.Catalog) Presenter { // GetImgPresenter returns a Json or Text presenter for images
func GetImgPresenter(option Option, s scope.Scope, c *pkg.Catalog) Presenter {
src := s.Source()
img := src.(scope.ImageSource).Img
switch option { switch option {
case JSONPresenter: case JSONPresenter:
return json_dirs.NewPresenter(catalog, path) return json_imgs.NewPresenter(img, c)
case TextPresenter: case TextPresenter:
return text_dirs.NewPresenter(catalog, path) return text_imgs.NewPresenter(img, c)
default:
return nil
}
}
// GetDirPresenter returns a Json or Text presenter for directories
func GetDirPresenter(option Option, s scope.Scope, c *pkg.Catalog) Presenter {
src := s.Source()
path := src.(scope.DirSource).Path
switch option {
case JSONPresenter:
return json_dirs.NewPresenter(c, path)
case TextPresenter:
return text_dirs.NewPresenter(c, path)
default: default:
return nil return nil
} }