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 FindDirect(cfg Config) []string
- func FindInAppNameSubdir(cfg Config) []string
- func FindInCwd(cfg Config) []string
- func FindInHomeDir(cfg Config) []string
- func FindInXDG(cfg Config) (out []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, values ...any) string
- func SummarizeCommand(cfg Config, cmd *cobra.Command, 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 PostLoader
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 FindDirect ¶
FindDirect attempts to find a directly configured cfg.File
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 IntPtrVarP ¶
IntPtrVarP adds an int pointer flag with no default
func StringPtrVarP ¶
StringPtrVarP adds a string pointer flag with no default
func SummarizeLocations ¶
Types ¶
type Config ¶
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) 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 defines effectively a subset of the methods exposed by pflag.FieldSet, 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 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