mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 14:36:33 +01:00
* expose underlying format options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove escape html options and address PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * incorporate PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
40 lines
836 B
Go
40 lines
836 B
Go
package options
|
|
|
|
import (
|
|
"github.com/hashicorp/go-multierror"
|
|
|
|
"github.com/anchore/syft/syft/format/spdxjson"
|
|
"github.com/anchore/syft/syft/sbom"
|
|
)
|
|
|
|
type FormatSPDXJSON struct {
|
|
Pretty *bool `yaml:"pretty" json:"pretty" mapstructure:"pretty"`
|
|
}
|
|
|
|
func DefaultFormatSPDXJSON() FormatSPDXJSON {
|
|
return FormatSPDXJSON{}
|
|
}
|
|
|
|
func (o FormatSPDXJSON) formatEncoders() ([]sbom.FormatEncoder, error) {
|
|
var (
|
|
encs []sbom.FormatEncoder
|
|
errs error
|
|
)
|
|
for _, v := range spdxjson.SupportedVersions() {
|
|
enc, err := spdxjson.NewFormatEncoderWithConfig(o.buildConfig(v))
|
|
if err != nil {
|
|
errs = multierror.Append(errs, err)
|
|
} else {
|
|
encs = append(encs, enc)
|
|
}
|
|
}
|
|
return encs, errs
|
|
}
|
|
|
|
func (o FormatSPDXJSON) buildConfig(v string) spdxjson.EncoderConfig {
|
|
return spdxjson.EncoderConfig{
|
|
Version: v,
|
|
Pretty: *o.Pretty,
|
|
}
|
|
}
|