Documentation
¶
Index ¶
- func AddFlags(log logger.Logger, flags *pflag.FlagSet, structs ...any)
- func BoolPtrVarP(flags *pflag.FlagSet, ptr **bool, name string, short string, usage string)
- func FindConfigYamlInCwd(_ Config) []string
- func FindInAppNameSubdir(cfg Config) []string
- func FindInCwd(cfg Config) []string
- func FindInHomeDir(cfg Config) []string
- func FindInXDG(cfg Config) (out []string)
- func Flatten(commaSeparatedEntries ...string) []string
- func Float64PtrVarP(flags *pflag.FlagSet, ptr **float64, name string, short string, usage string)
- func IntPtrVarP(flags *pflag.FlagSet, ptr **int, name string, short string, usage string)
- func Load(cfg Config, cmd *cobra.Command, configurations ...any) error
- func LoadAt(cfg Config, cmd *cobra.Command, path string, configuration any) error
- func StringPtrVarP(flags *pflag.FlagSet, ptr **string, name string, short string, usage string)
- func Summarize(cfg Config, descriptions DescriptionProvider, filter ValueFilterFunc, ...) string
- func SummarizeCommand(cfg Config, cmd *cobra.Command, filter ValueFilterFunc, values ...any) string
- func SummarizeLocations(cfg Config) (out []string)
- type Config
- type DescriptionProvider
- type FieldDescriber
- type FieldDescriptionSet
- type FieldDescriptionSetProvider
- type Finder
- type FlagAdder
- type FlagSet
- type PFlagSetProvider
- type PostLoader
- type ValueFilterFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFlags ¶
AddFlags traverses the object graphs from the structs provided and calls all AddFlags methods implemented on them
func BoolPtrVarP ¶
BoolPtrVarP adds a boolean pointer flag with no default
func FindConfigYamlInCwd ¶
FindConfigYamlInCwd looks for ./config.yaml -- NOTE: this is not part of the default behavior
func FindInAppNameSubdir ¶
FindInAppNameSubdir looks for ./.<appname>/config.<ext>
func FindInHomeDir ¶
FindInHomeDir looks for ~/.<appname>.<ext>
func FindInXDG ¶
FindInXDG looks for <appname>/config.yaml in xdg locations, starting with xdg home config dir then moving upwards
func Flatten ¶
Flatten takes multiple entries and creates a "flattened" list by further splitting comma-separated entries and removing empty entries
func Float64PtrVarP ¶
Float64PtrVarP adds a float64 pointer flag with no default
func IntPtrVarP ¶
IntPtrVarP adds an int pointer flag with no default
func StringPtrVarP ¶
StringPtrVarP adds a string pointer flag with no default
func Summarize ¶
func Summarize(cfg Config, descriptions DescriptionProvider, filter ValueFilterFunc, values ...any) string
func SummarizeCommand ¶
func SummarizeLocations ¶
Types ¶
type Config ¶
type Config struct { // Logger should be provided for Fangs to log output Logger logger.Logger `yaml:"-" json:"-" mapstructure:"-"` // AppName is used to specify the name of files and environment variables to look for AppName string `yaml:"-" json:"-" mapstructure:"-"` // TagName is the struct tag to use for configuration structure field names (defaults to mapstructure) TagName string `yaml:"-" json:"-" mapstructure:"-"` // MultiFile allows for multiple configuration files, including hierarchical inheritance of files found in search locations when no files directly specified MultiFile bool `yaml:"-" json:"-" mapstructure:"-"` // Files is where configuration files are specified Files []string `yaml:"-" json:"-" mapstructure:"-"` // Finders are used to search for configuration when no files explicitly specified Finders []Finder `yaml:"-" json:"-" mapstructure:"-"` // ProfileKey is the top-level configuration key to define profiles ProfileKey string `yaml:"-" json:"-" mapstructure:"-"` // Profiles specific profiles to load Profiles []string `yaml:"-" json:"-" mapstructure:"-"` }
func (Config) WithConfigEnvVar ¶
WithConfigEnvVar looks for the environment variable: <APP_NAME>_CONFIG as a way to specify a config file This will be overridden by a command-line flag
type DescriptionProvider ¶
type DescriptionProvider interface {
GetDescription(value reflect.Value, field reflect.StructField) string
}
func DescriptionProviders ¶
func DescriptionProviders(providers ...DescriptionProvider) DescriptionProvider
func NewCommandFlagDescriptionProvider ¶
func NewCommandFlagDescriptionProvider(tagName string, cmd *cobra.Command) DescriptionProvider
func NewFieldDescriber ¶
func NewFieldDescriber(cfgs ...any) DescriptionProvider
func NewStructDescriptionTagProvider ¶
func NewStructDescriptionTagProvider() DescriptionProvider
NewStructDescriptionTagProvider returns a DescriptionProvider that returns "description" field tag values
type FieldDescriber ¶
type FieldDescriber interface {
DescribeFields(descriptions FieldDescriptionSet)
}
FieldDescriber a struct implementing this interface will have DescribeFields called when Summarize is called
type FieldDescriptionSet ¶
FieldDescriptionSet accepts field descriptions
type FieldDescriptionSetProvider ¶
type FieldDescriptionSetProvider interface { DescriptionProvider FieldDescriptionSet }
FieldDescriptionSetProvider implements both DescriptionProvider and FieldDescriptionSet
func NewDirectDescriber ¶
func NewDirectDescriber() FieldDescriptionSetProvider
type FlagAdder ¶
type FlagAdder interface {
AddFlags(flags FlagSet)
}
FlagAdder interface can be implemented by structs in order to add flags when AddFlags is called
type FlagSet ¶
type FlagSet interface { BoolVarP(p *bool, name, shorthand, usage string) BoolPtrVarP(p **bool, name, shorthand, usage string) Float64VarP(p *float64, name, shorthand, usage string) CountVarP(p *int, name, shorthand, usage string) IntVarP(p *int, name, shorthand, usage string) StringVarP(p *string, name, shorthand, usage string) StringArrayVarP(p *[]string, name, shorthand, usage string) }
FlagSet is a facade of pflag.FlagSet, as fangs requires all flag add calls to use field references in order to match reading configuration and summarization information. The methods do not take default values, however, which should be set on the struct directly. There is one additional method: BoolPtrVarP, which allows for adding flags for bool pointers, needed by some multi-level configurations.
func NewPFlagSet ¶
type PFlagSetProvider ¶
PFlagSetProvider provides access to the underlying pflag.FlagSet; the FlagSet may be type asserted to this interface
WARNING: only use this when the fangs API does not provide a necessary feature, such as marking a flag as deprecated. Using the pflag.FlagSet directly may result in a mismatch between flags and configuration.
type PostLoader ¶
type PostLoader interface {
PostLoad() error
}
PostLoader is the interface used to do any sort of processing after `config.Load` has been called. This runs after the entire struct has been populated from the configuration files and environment variables