github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/internal/config/cataloger_options.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/spf13/viper"
     7  
     8  	"github.com/kastenhq/syft/syft/source"
     9  )
    10  
    11  type catalogerOptions struct {
    12  	Enabled  bool         `yaml:"enabled" json:"enabled" mapstructure:"enabled"`
    13  	Scope    string       `yaml:"scope" json:"scope" mapstructure:"scope"`
    14  	ScopeOpt source.Scope `yaml:"-" json:"-"`
    15  }
    16  
    17  func (cfg catalogerOptions) loadDefaultValues(v *viper.Viper) {
    18  	v.SetDefault("package.cataloger.enabled", true)
    19  }
    20  
    21  func (cfg *catalogerOptions) parseConfigValues() error {
    22  	scopeOption := source.ParseScope(cfg.Scope)
    23  	if scopeOption == source.UnknownScope {
    24  		return fmt.Errorf("bad scope value %q", cfg.Scope)
    25  	}
    26  	cfg.ScopeOpt = scopeOption
    27  
    28  	return nil
    29  }