github.com/anchore/syft@v1.38.2/cmd/syft/internal/options/license.go (about)

     1  package options
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/anchore/clio"
     7  	"github.com/anchore/syft/internal"
     8  	"github.com/anchore/syft/syft/cataloging"
     9  )
    10  
    11  type licenseConfig struct {
    12  	Content                 cataloging.LicenseContent   `yaml:"content" json:"content" mapstructure:"content"`
    13  	Coverage                float64                     `yaml:"coverage" json:"coverage" mapstructure:"coverage"`
    14  	AvailableLicenseContent []cataloging.LicenseContent `yaml:"-" json:"-" mapstructure:"-"`
    15  }
    16  
    17  var _ interface {
    18  	clio.FieldDescriber
    19  } = (*licenseConfig)(nil)
    20  
    21  func (o *licenseConfig) DescribeFields(descriptions clio.FieldDescriptionSet) {
    22  	descriptions.Add(&o.Content, fmt.Sprintf("include the content of licenses in the SBOM for a given syft scan; valid values are: %s", o.AvailableLicenseContent))
    23  
    24  	descriptions.Add(&o.Coverage, `adjust the percent as a fraction of the total text, in normalized words, that
    25  matches any valid license for the given inputs, expressed as a percentage across all of the licenses matched.`)
    26  }
    27  
    28  func (o *licenseConfig) PostLoad() error {
    29  	validContent := internal.NewSet(o.AvailableLicenseContent...)
    30  	if !validContent.Contains(o.Content) {
    31  		return fmt.Errorf("could not use %q as license content option; valid values are: %v", o.Content, validContent.ToSlice())
    32  	}
    33  	return nil
    34  }
    35  
    36  func defaultLicenseConfig() licenseConfig {
    37  	cfg := cataloging.DefaultLicenseConfig()
    38  	return licenseConfig{
    39  		Content:  cfg.IncludeContent,
    40  		Coverage: cfg.Coverage,
    41  		AvailableLicenseContent: []cataloging.LicenseContent{
    42  			cataloging.LicenseContentIncludeAll,
    43  			cataloging.LicenseContentIncludeUnknown,
    44  			cataloging.LicenseContentExcludeAll,
    45  		},
    46  	}
    47  }