mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
* split up sbom.Format into encode and decode ops Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * update cmd pkg to inject format configs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * bump cyclonedx schema to 1.5 Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * redact image metadata from github encoder tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add more testing around format decoder identify Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add test case for format version options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix CLI test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * [wip] - review comments Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep encoder creation out of post load function Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep decider and identify functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add a few more doc comments Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove format encoder default function helpers Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * address PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * move back to streaming based decode functions Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * with common convention for encoder constructors Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix tests and allow for encoders to be created from cli options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli tests Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix linting Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * buffer reads from stdin to support seeking Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package options
|
|
|
|
import (
|
|
"github.com/anchore/clio"
|
|
"github.com/anchore/fangs"
|
|
"github.com/anchore/syft/syft/sbom"
|
|
)
|
|
|
|
var _ interface {
|
|
clio.FlagAdder
|
|
clio.PostLoader
|
|
} = (*OutputFile)(nil)
|
|
|
|
// Deprecated: OutputFile supports the --file to write the SBOM output to
|
|
type OutputFile struct {
|
|
Enabled bool `yaml:"-" json:"-" mapstructure:"-"`
|
|
File string `yaml:"file" json:"file" mapstructure:"file"`
|
|
}
|
|
|
|
func (o *OutputFile) AddFlags(flags clio.FlagSet) {
|
|
if o.Enabled {
|
|
flags.StringVarP(&o.File, "file", "",
|
|
"file to write the default report output to (default is STDOUT)")
|
|
|
|
if pfp, ok := flags.(fangs.PFlagSetProvider); ok {
|
|
flagSet := pfp.PFlagSet()
|
|
flagSet.Lookup("file").Deprecated = "use: output"
|
|
}
|
|
}
|
|
}
|
|
|
|
func (o *OutputFile) PostLoad() error {
|
|
if !o.Enabled {
|
|
return nil
|
|
}
|
|
if o.File != "" {
|
|
file, err := expandFilePath(o.File)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
o.File = file
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (o *OutputFile) SBOMWriter(f sbom.FormatEncoder) (sbom.Writer, error) {
|
|
if !o.Enabled {
|
|
return nil, nil
|
|
}
|
|
writer, err := newSBOMMultiWriter(newSBOMWriterDescription(f, o.File))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return writer, nil
|
|
}
|