github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/cmd/syft/cli/options/format_syft_json.go (about) 1 package options 2 3 import ( 4 "github.com/anchore/syft/syft/format/syftjson" 5 "github.com/anchore/syft/syft/sbom" 6 ) 7 8 type FormatSyftJSON struct { 9 Legacy bool `yaml:"legacy" json:"legacy" mapstructure:"legacy"` 10 Pretty *bool `yaml:"pretty" json:"pretty" mapstructure:"pretty"` 11 } 12 13 func DefaultFormatJSON() FormatSyftJSON { 14 return FormatSyftJSON{ 15 Legacy: false, 16 } 17 } 18 19 func (o FormatSyftJSON) formatEncoders() ([]sbom.FormatEncoder, error) { 20 enc, err := syftjson.NewFormatEncoderWithConfig(o.buildConfig()) 21 return []sbom.FormatEncoder{enc}, err 22 } 23 24 func (o FormatSyftJSON) buildConfig() syftjson.EncoderConfig { 25 var pretty bool 26 if o.Pretty != nil { 27 pretty = *o.Pretty 28 } 29 return syftjson.EncoderConfig{ 30 Legacy: o.Legacy, 31 Pretty: pretty, 32 } 33 }