mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
replace presenter.Option with format.Option
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
12b44af471
commit
124cfd86c7
@ -6,6 +6,8 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/anchore/syft/syft/format"
|
||||
|
||||
"github.com/anchore/stereoscope"
|
||||
"github.com/anchore/syft/internal"
|
||||
"github.com/anchore/syft/internal/anchore"
|
||||
@ -48,7 +50,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
packagesPresenterOpt packages.PresenterOption
|
||||
packagesPresenterOpt format.Option
|
||||
packagesArgs = cobra.MaximumNArgs(1)
|
||||
packagesCmd = &cobra.Command{
|
||||
Use: "packages [SOURCE]",
|
||||
@ -71,8 +73,8 @@ var (
|
||||
}
|
||||
|
||||
// set the presenter
|
||||
presenterOption := packages.ParsePresenterOption(appConfig.Output)
|
||||
if presenterOption == packages.UnknownPresenterOption {
|
||||
presenterOption := format.ParseOption(appConfig.Output)
|
||||
if presenterOption == format.UnknownOption {
|
||||
return fmt.Errorf("bad --output value '%s'", appConfig.Output)
|
||||
}
|
||||
packagesPresenterOpt = presenterOption
|
||||
@ -109,8 +111,8 @@ func setPackageFlags(flags *pflag.FlagSet) {
|
||||
fmt.Sprintf("selection of layers to catalog, options=%v", source.AllScopes))
|
||||
|
||||
flags.StringP(
|
||||
"output", "o", string(packages.TablePresenterOption),
|
||||
fmt.Sprintf("report output formatter, options=%v", packages.AllPresenters),
|
||||
"output", "o", string(format.TableOption),
|
||||
fmt.Sprintf("report output formatter, options=%v", format.AllOptions),
|
||||
)
|
||||
|
||||
flags.StringP(
|
||||
@ -247,7 +249,7 @@ func packagesExecWorker(userInput string) <-chan error {
|
||||
|
||||
bus.Publish(partybus.Event{
|
||||
Type: event.PresenterReady,
|
||||
Value: packages.Presenter(packagesPresenterOpt, packages.PresenterConfig{
|
||||
Value: packages.Presenter(packagesPresenterOpt, packages.Config{
|
||||
SourceMetadata: src.Metadata,
|
||||
Catalog: catalog,
|
||||
Distro: d,
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
type PresenterConfig struct {
|
||||
type Config struct {
|
||||
SourceMetadata source.Metadata
|
||||
Catalog *pkg.Catalog
|
||||
Distro *distro.Distro
|
||||
@ -5,26 +5,30 @@ a specific Presenter implementation given user configuration.
|
||||
package packages
|
||||
|
||||
import (
|
||||
"github.com/anchore/syft/internal/formats"
|
||||
"github.com/anchore/syft/internal/presenter/packages"
|
||||
"github.com/anchore/syft/syft/format"
|
||||
"github.com/anchore/syft/syft/presenter"
|
||||
)
|
||||
|
||||
// Presenter returns a presenter for images or directories
|
||||
func Presenter(option PresenterOption, config PresenterConfig) presenter.Presenter {
|
||||
switch option {
|
||||
case JSONPresenterOption:
|
||||
return packages.NewJSONPresenter(config.Catalog, config.SourceMetadata, config.Distro, config.Scope)
|
||||
case TextPresenterOption:
|
||||
func Presenter(o format.Option, config Config) presenter.Presenter {
|
||||
// TODO: This function will be removed in the future
|
||||
switch o {
|
||||
case format.TextOption:
|
||||
return packages.NewTextPresenter(config.Catalog, config.SourceMetadata)
|
||||
case TablePresenterOption:
|
||||
case format.TableOption:
|
||||
return packages.NewTablePresenter(config.Catalog)
|
||||
case CycloneDxPresenterOption:
|
||||
case format.CycloneDxOption:
|
||||
return packages.NewCycloneDxPresenter(config.Catalog, config.SourceMetadata)
|
||||
case SPDXTagValuePresenterOption:
|
||||
case format.SPDXTagValueOption:
|
||||
return packages.NewSPDXTagValuePresenter(config.Catalog, config.SourceMetadata)
|
||||
case SPDXJSONPresenterOption:
|
||||
return packages.NewSPDXJSONPresenter(config.Catalog, config.SourceMetadata)
|
||||
default:
|
||||
return nil
|
||||
// TODO: this is the new way of getting presenters from formats
|
||||
f := formats.ByOption(o)
|
||||
if f == nil {
|
||||
return nil
|
||||
}
|
||||
return f.Presenter(config.Catalog, &config.SourceMetadata, config.Distro)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
package packages
|
||||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
UnknownPresenterOption PresenterOption = "UnknownPresenterOption"
|
||||
JSONPresenterOption PresenterOption = "json"
|
||||
TextPresenterOption PresenterOption = "text"
|
||||
TablePresenterOption PresenterOption = "table"
|
||||
CycloneDxPresenterOption PresenterOption = "cyclonedx"
|
||||
SPDXTagValuePresenterOption PresenterOption = "spdx-tag-value"
|
||||
SPDXJSONPresenterOption PresenterOption = "spdx-json"
|
||||
)
|
||||
|
||||
var AllPresenters = []PresenterOption{
|
||||
JSONPresenterOption,
|
||||
TextPresenterOption,
|
||||
TablePresenterOption,
|
||||
CycloneDxPresenterOption,
|
||||
SPDXTagValuePresenterOption,
|
||||
SPDXJSONPresenterOption,
|
||||
}
|
||||
|
||||
type PresenterOption string
|
||||
|
||||
func ParsePresenterOption(userStr string) PresenterOption {
|
||||
switch strings.ToLower(userStr) {
|
||||
case string(JSONPresenterOption):
|
||||
return JSONPresenterOption
|
||||
case string(TextPresenterOption):
|
||||
return TextPresenterOption
|
||||
case string(TablePresenterOption):
|
||||
return TablePresenterOption
|
||||
case string(CycloneDxPresenterOption), "cyclone", "cyclone-dx":
|
||||
return CycloneDxPresenterOption
|
||||
case string(SPDXTagValuePresenterOption), "spdx", "spdx-tagvalue", "spdxtagvalue", "spdx-tv":
|
||||
return SPDXTagValuePresenterOption
|
||||
case string(SPDXJSONPresenterOption), "spdxjson":
|
||||
return SPDXJSONPresenterOption
|
||||
default:
|
||||
return UnknownPresenterOption
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
package presenter
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// Presenter defines the expected behavior for an object responsible for displaying arbitrary input and processed data
|
||||
// to a given io.Writer.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user