Documentation
¶
Index ¶
- Constants
- Variables
- func AddFieldByMappedOption(opts OptionValueProvider, oname string, config Config, ...) error
- func AddFieldByMappedOptionP(opts OptionValueProvider, p NameProvider, config Config, ...) error
- func AddFieldByOption(opts OptionValueProvider, oname string, config Config, names ...string) error
- func AddFieldByOptionP(opts OptionValueProvider, p NameProvider, config Config, names ...string) error
- func AddGroups(list []string, groups ...string) []string
- func AddPrefix(prefix string, values ...string) []string
- func FormatOptions(handler OptionTypeSet) string
- func GetField(config Config, names ...string) (interface{}, error)
- func KindVersion(t string) (string, string)
- func NewTypedConfigProviderBase(name string, desc string, prov TypeNameProvider, acceptUnknown bool, ...) *typedConfigProviderBase
- func OptionSpec(otype OptionType, args ...string) _OptionSpec
- func OptionString(option OptionType) string
- func OptionStrings(types ...OptionType) []string
- func ParseOptionsFor(flags *pflag.FlagSet, specs ..._OptionSpec) error
- func SetField(config Config, value interface{}, names ...string) error
- func TypeName(args ...string) string
- func UnmarshalConfig(cfg Config, target any) error
- type BoolOption
- type BoolOptionType
- type BytesOption
- type BytesOptionType
- type Config
- type ConfigAdder
- type ConfigHandler
- type ConfigOptionTypeSetHandler
- type ConfigProvider
- type ExplicitlyTypedConfigTypeOptionSetConfigProvider
- type Filter
- type IdentityPathOption
- type IdentityPathOptionType
- type IntOption
- type IntOptionType
- type NameProvider
- type Option
- type OptionBase
- type OptionName
- type OptionType
- func NewBoolOptionType(name string, description string) OptionType
- func NewBytesOptionType(name string, description string) OptionType
- func NewIdentityPathOptionType(name string, description string) OptionType
- func NewIntOptionType(name string, description string) OptionType
- func NewPathArrayOptionType(name string, description string) OptionType
- func NewPathOptionType(name string, description string) OptionType
- func NewStringArrayOptionType(name string, description string) OptionType
- func NewStringMapOptionType(name string, description string) OptionType
- func NewStringOptionType(name string, description string) OptionType
- func NewStringSliceMapColonOptionType(name string, description string) OptionType
- func NewStringSliceMapOptionType(name string, description string) OptionType
- func NewValueMapOptionType(name string, description string) OptionType
- func NewValueMapYAMLOptionType(name string, description string) OptionType
- func NewYAMLOptionType(name string, description string) OptionType
- type OptionTypeSet
- type OptionValueProvider
- type Options
- type PathArrayOption
- type PathArrayOptionType
- type PathOption
- type PathOptionType
- type StringArrayOption
- type StringArrayOptionType
- type StringMapOption
- type StringMapOptionType
- type StringOption
- type StringOptionType
- type StringSliceMapColonOption
- type StringSliceMapColonOptionType
- type StringSliceMapOption
- type StringSliceMapOptionType
- type TypeNameProvider
- type TypeOptionBase
- type TypedOptionSetConfigProvider
- type ValueMapOption
- type ValueMapOptionType
- type ValueMapYAMLOption
- type ValueMapYAMLOptionType
- type YAMLOption
- type YAMLOptionType
Constants ¶
const VersionSeparator = "/"
Variables ¶
var NopConfigHandler = NewNopConfigHandler()
NopConfigHandler is a dummy config handler doing nothing.
Functions ¶
func AddFieldByMappedOption ¶
func AddFieldByMappedOptionP ¶
func AddFieldByMappedOptionP(opts OptionValueProvider, p NameProvider, config Config, mapper func(interface{}) (interface{}, error), names ...string) error
func AddFieldByOption ¶
func AddFieldByOption(opts OptionValueProvider, oname string, config Config, names ...string) error
AddFieldByOption sets the specified target field with the option value, if given. If no target field is specified the name of the option is used.
func AddFieldByOptionP ¶
func AddFieldByOptionP(opts OptionValueProvider, p NameProvider, config Config, names ...string) error
AddFieldByOptionP sets the specified target field with the option value, if given. The option is specified by a name provider instead of its name. If no target field is specified the name of the option is used.
func FormatOptions ¶
func FormatOptions(handler OptionTypeSet) string
func KindVersion ¶
func NewTypedConfigProviderBase ¶
func NewTypedConfigProviderBase(name string, desc string, prov TypeNameProvider, acceptUnknown bool, types ...OptionType) *typedConfigProviderBase
NewTypedConfigProviderBase provides a base implementation for a ConfigProvider distinguishing among multiple config variants. Variants are given by nested OptionSets. Those sets must implement ConfigProvider to be able to // extract appropriate config. The actual variant is selected by a TypeNameProvider, typically from the actually given option settings. It uses an additional (plain) config option with the name of the provider accepting a structured value using a YAML option type. If this option is give , its value is used as Config value set. The type name might then be specified via the attribute `type`. It is selected if the TypeNameProvider is able to deliver a type name. If any Option of the set is given, the type setting is required, also.
func OptionSpec ¶
func OptionSpec(otype OptionType, args ...string) _OptionSpec
func OptionString ¶
func OptionString(option OptionType) string
func OptionStrings ¶
func OptionStrings(types ...OptionType) []string
func ParseOptionsFor ¶
func UnmarshalConfig ¶
UnmarshalConfig uses JSON to configure a target object with a given Config. The object type must match the ConfigOptionTypeSetHandler used to create the Config from an OptionSet.
Types ¶
type BoolOption ¶
type BoolOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*BoolOption) AddFlags ¶
func (o *BoolOption) AddFlags(fs *pflag.FlagSet)
func (*BoolOption) Value ¶
func (o *BoolOption) Value() interface{}
type BoolOptionType ¶
type BoolOptionType struct {
TypeOptionBase
}
func (*BoolOptionType) Create ¶
func (s *BoolOptionType) Create() Option
func (*BoolOptionType) Equal ¶
func (s *BoolOptionType) Equal(optionType OptionType) bool
type BytesOption ¶
type BytesOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*BytesOption) AddFlags ¶
func (o *BytesOption) AddFlags(fs *pflag.FlagSet)
func (*BytesOption) Value ¶
func (o *BytesOption) Value() interface{}
type BytesOptionType ¶
type BytesOptionType struct {
TypeOptionBase
}
func (*BytesOptionType) Create ¶
func (s *BytesOptionType) Create() Option
func (*BytesOptionType) Equal ¶
func (s *BytesOptionType) Equal(optionType OptionType) bool
type Config ¶
type Config = map[string]interface{}
Config is a generic structured config stored in a string map.
type ConfigAdder ¶
ConfigAdder is used to incorporate a partial config into an existing one.
func ComposedAdder ¶
func ComposedAdder(adders ...ConfigAdder) ConfigAdder
func (ConfigAdder) ApplyConfig ¶
func (c ConfigAdder) ApplyConfig(options Options, config Config) error
type ConfigHandler ¶
ConfigHandler describes the ConfigAdder functionality. It is used to apply Options to a Config.
func NewNopConfigHandler ¶
func NewNopConfigHandler() ConfigHandler
type ConfigOptionTypeSetHandler ¶
type ConfigOptionTypeSetHandler interface {
OptionTypeSet
ConfigHandler
}
ConfigOptionTypeSetHandler describes a OptionTypeSet, which also provides the possibility to provide config.
func NewConfigOptionTypeSetHandler ¶
func NewConfigOptionTypeSetHandler(name string, adder ConfigAdder, types ...OptionType) ConfigOptionTypeSetHandler
NewConfigOptionTypeSetHandler creates a new ConfigOptionTypeSetHandler based on a ConfigAdder and a set of [OptionType]s.
type ConfigProvider ¶
type ConfigProvider interface {
CreateOptions() Options
GetConfigFor(opts Options) (Config, error)
}
ConfigProvider is able to create a set of command line [Option]s in form of an OptionSet and extract a Config from Options (might be a super set).
type ExplicitlyTypedConfigTypeOptionSetConfigProvider ¶
type ExplicitlyTypedConfigTypeOptionSetConfigProvider interface {
TypedOptionSetConfigProvider
SetTypeName(n string)
}
func NewExplicitlyTypedConfigProvider ¶
func NewExplicitlyTypedConfigProvider(name string, desc string, acceptUnknown ...bool) ExplicitlyTypedConfigTypeOptionSetConfigProvider
NewExplicitlyTypedConfigProvider provides a ConfigProvider using a fixed type name. OptionTypes and fixed type must be added separately.
type IdentityPathOption ¶
type IdentityPathOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*IdentityPathOption) AddFlags ¶
func (o *IdentityPathOption) AddFlags(fs *pflag.FlagSet)
func (*IdentityPathOption) Value ¶
func (o *IdentityPathOption) Value() interface{}
type IdentityPathOptionType ¶
type IdentityPathOptionType struct {
TypeOptionBase
}
func (*IdentityPathOptionType) Create ¶
func (s *IdentityPathOptionType) Create() Option
func (*IdentityPathOptionType) Equal ¶
func (s *IdentityPathOptionType) Equal(optionType OptionType) bool
type IntOption ¶
type IntOption struct {
OptionBase
// contains filtered or unexported fields
}
type IntOptionType ¶
type IntOptionType struct {
TypeOptionBase
}
func (*IntOptionType) Create ¶
func (s *IntOptionType) Create() Option
func (*IntOptionType) Equal ¶
func (s *IntOptionType) Equal(optionType OptionType) bool
type NameProvider ¶
type NameProvider interface {
GetName() string
}
type Option ¶
type Option interface {
flagutils.Options
GetName() string
AddGroups(groups ...string)
GetGroups() []string
Changed() bool
Value() interface{}
}
Option is a single options with a name and a value, which can be added to a pflag.FlagSet. It might belong to arbitrary number of groups. After evaluation of the pflag.FlagSet against a set of arguments it provides information about the actual value and the changed state.
type OptionBase ¶
type OptionBase struct {
// contains filtered or unexported fields
}
func NewOptionBase ¶
func NewOptionBase(otyp OptionType) OptionBase
func (*OptionBase) AddGroups ¶
func (b *OptionBase) AddGroups(groups ...string)
func (*OptionBase) Changed ¶
func (b *OptionBase) Changed() bool
func (*OptionBase) Description ¶
func (b *OptionBase) Description() string
func (*OptionBase) GetGroups ¶
func (b *OptionBase) GetGroups() []string
func (*OptionBase) GetName ¶
func (b *OptionBase) GetName() string
func (*OptionBase) TweakFlag ¶
func (b *OptionBase) TweakFlag(f *pflag.Flag)
func (*OptionBase) Type ¶
func (b *OptionBase) Type() OptionType
type OptionName ¶
type OptionName string
func (OptionName) GetName ¶
func (n OptionName) GetName() string
type OptionType ¶
type OptionType interface {
GetName() string
GetDescription() string
Create() Option
Equal(optionType OptionType) bool
}
OptionType describes a particular type of option It has a name and a description, and can be used to create an Option instance with the same name, which can be added to a pflag.FlagSet, Every Optiontype has a technical type (the type of the underlying pflag.Flag. Two typed are identical if name, description and technical type are identical.
func NewBoolOptionType ¶
func NewBoolOptionType(name string, description string) OptionType
func NewBytesOptionType ¶
func NewBytesOptionType(name string, description string) OptionType
func NewIdentityPathOptionType ¶
func NewIdentityPathOptionType(name string, description string) OptionType
func NewIntOptionType ¶
func NewIntOptionType(name string, description string) OptionType
func NewPathArrayOptionType ¶
func NewPathArrayOptionType(name string, description string) OptionType
func NewPathOptionType ¶
func NewPathOptionType(name string, description string) OptionType
func NewStringArrayOptionType ¶
func NewStringArrayOptionType(name string, description string) OptionType
func NewStringMapOptionType ¶
func NewStringMapOptionType(name string, description string) OptionType
func NewStringOptionType ¶
func NewStringOptionType(name string, description string) OptionType
func NewStringSliceMapColonOptionType ¶
func NewStringSliceMapColonOptionType(name string, description string) OptionType
func NewStringSliceMapOptionType ¶
func NewStringSliceMapOptionType(name string, description string) OptionType
func NewValueMapOptionType ¶
func NewValueMapOptionType(name string, description string) OptionType
func NewValueMapYAMLOptionType ¶
func NewValueMapYAMLOptionType(name string, description string) OptionType
func NewYAMLOptionType ¶
func NewYAMLOptionType(name string, description string) OptionType
type OptionTypeSet ¶
type OptionTypeSet interface {
AddGroups(groups ...string)
GetName() string
Size() int
OptionTypes() []OptionType
OptionTypeNames() []string
HasOptionType(name string) bool
GetOptionType(name string) OptionType
GetTypeSet(name string) OptionTypeSet
OptionTypeSets() []OptionTypeSet
AddOptionType(OptionType) error
AddTypeSet(OptionTypeSet) error
AddAll(o OptionTypeSet) (duplicated OptionTypeSet, err error)
Close(funcs ...func([]OptionType) error) error
CreateOptions() Options
AddGroupsToOption(o Option)
}
OptionTypeSet represents the type for a set of [Option]s by describing the set of [OptionType]s. It has a name and nested [OptionType]s. This nesting could be described by other [OptionTypeSet]s. [OptionType]s hereby, might be shared with nested Sets, if their technical type matches. In an OptionTypeSet the names must be unique. If a nested set contains the same name as the nesting one (or two nested sets contain the same name) the option types must be identical.
func NewOptionTypeSet ¶
func NewOptionTypeSet(name string, types ...OptionType) OptionTypeSet
type OptionValueProvider ¶
OptionValueProvider provides values for named options.
type Options ¶
type Options interface {
flagutils.Options
AddTypeSetGroupsToOptions(set OptionTypeSet)
Options() []Option
Names() []string
Size() int
HasOption(name string) bool
Check(set OptionTypeSet, desc string) error
GetValue(name string) (interface{}, bool)
Changed(names ...string) bool
FilterBy(Filter) Options
}
Options is a set of arbitrary command line options. This set can be added to a pflag.FlagSet. After evaluation of the flag set against a set of arguments it provides information about the actual value and the changed state.
func NewOptions ¶
func NewOptionsByList ¶
type PathArrayOption ¶
type PathArrayOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*PathArrayOption) AddFlags ¶
func (o *PathArrayOption) AddFlags(fs *pflag.FlagSet)
func (*PathArrayOption) Value ¶
func (o *PathArrayOption) Value() interface{}
type PathArrayOptionType ¶
type PathArrayOptionType struct {
TypeOptionBase
}
func (*PathArrayOptionType) Create ¶
func (s *PathArrayOptionType) Create() Option
func (*PathArrayOptionType) Equal ¶
func (s *PathArrayOptionType) Equal(optionType OptionType) bool
type PathOption ¶
type PathOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*PathOption) AddFlags ¶
func (o *PathOption) AddFlags(fs *pflag.FlagSet)
func (*PathOption) Value ¶
func (o *PathOption) Value() interface{}
type PathOptionType ¶
type PathOptionType struct {
TypeOptionBase
}
func (*PathOptionType) Create ¶
func (s *PathOptionType) Create() Option
func (*PathOptionType) Equal ¶
func (s *PathOptionType) Equal(optionType OptionType) bool
type StringArrayOption ¶
type StringArrayOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*StringArrayOption) AddFlags ¶
func (o *StringArrayOption) AddFlags(fs *pflag.FlagSet)
func (*StringArrayOption) Value ¶
func (o *StringArrayOption) Value() interface{}
type StringArrayOptionType ¶
type StringArrayOptionType struct {
TypeOptionBase
}
func (*StringArrayOptionType) Create ¶
func (s *StringArrayOptionType) Create() Option
func (*StringArrayOptionType) Equal ¶
func (s *StringArrayOptionType) Equal(optionType OptionType) bool
type StringMapOption ¶
type StringMapOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*StringMapOption) AddFlags ¶
func (o *StringMapOption) AddFlags(fs *pflag.FlagSet)
func (*StringMapOption) Value ¶
func (o *StringMapOption) Value() interface{}
type StringMapOptionType ¶
type StringMapOptionType struct {
TypeOptionBase
}
func (*StringMapOptionType) Create ¶
func (s *StringMapOptionType) Create() Option
func (*StringMapOptionType) Equal ¶
func (s *StringMapOptionType) Equal(optionType OptionType) bool
type StringOption ¶
type StringOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*StringOption) AddFlags ¶
func (o *StringOption) AddFlags(fs *pflag.FlagSet)
func (*StringOption) Value ¶
func (o *StringOption) Value() interface{}
type StringOptionType ¶
type StringOptionType struct {
TypeOptionBase
}
func (*StringOptionType) Create ¶
func (s *StringOptionType) Create() Option
func (*StringOptionType) Equal ¶
func (s *StringOptionType) Equal(optionType OptionType) bool
type StringSliceMapColonOption ¶
type StringSliceMapColonOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*StringSliceMapColonOption) AddFlags ¶
func (o *StringSliceMapColonOption) AddFlags(fs *pflag.FlagSet)
func (*StringSliceMapColonOption) Value ¶
func (o *StringSliceMapColonOption) Value() interface{}
type StringSliceMapColonOptionType ¶
type StringSliceMapColonOptionType struct {
TypeOptionBase
}
func (*StringSliceMapColonOptionType) Create ¶
func (s *StringSliceMapColonOptionType) Create() Option
func (*StringSliceMapColonOptionType) Equal ¶
func (s *StringSliceMapColonOptionType) Equal(optionType OptionType) bool
type StringSliceMapOption ¶
type StringSliceMapOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*StringSliceMapOption) AddFlags ¶
func (o *StringSliceMapOption) AddFlags(fs *pflag.FlagSet)
func (*StringSliceMapOption) Value ¶
func (o *StringSliceMapOption) Value() interface{}
type StringSliceMapOptionType ¶
type StringSliceMapOptionType struct {
TypeOptionBase
}
func (*StringSliceMapOptionType) Create ¶
func (s *StringSliceMapOptionType) Create() Option
func (*StringSliceMapOptionType) Equal ¶
func (s *StringSliceMapOptionType) Equal(optionType OptionType) bool
type TypeNameProvider ¶
func TypeNameProviderFromOptions ¶
func TypeNameProviderFromOptions(name string) TypeNameProvider
TypeNameProviderFromOptions offers a function extractiong a type name from the given option name. The Option's value must be a string. which is used a type name.
type TypeOptionBase ¶
type TypeOptionBase struct {
// contains filtered or unexported fields
}
func (*TypeOptionBase) GetDescription ¶
func (b *TypeOptionBase) GetDescription() string
func (*TypeOptionBase) GetName ¶
func (b *TypeOptionBase) GetName() string
type TypedOptionSetConfigProvider ¶
type TypedOptionSetConfigProvider interface {
ConfigProvider
OptionTypeSet
GetPlainOptionType() OptionType
GetTypeOptionType() OptionType
// IsExplicitlySelected returns, whether the provider is
// selected by the given options.
IsExplicitlySelected(opts Options) bool
}
TypedOptionSetConfigProvider is ConfigProvider based on an OptionTypeSet with a dedicated OptionType used to ???.
func NewPlainConfigProvider ¶
func NewPlainConfigProvider(name string, adder ConfigAdder, types ...OptionType) TypedOptionSetConfigProvider
NewPlainConfigProvider create a TypedOptionSetConfigProvider without using a selective OptionType. The provided is selected if any option of the described OptionTypeSet has been given by the command line (no selective option type given). It can provide a Config from given Options.
func NewTypedConfigProvider ¶
func NewTypedConfigProvider(name string, desc, typeOption string, acceptUnknown ...bool) TypedOptionSetConfigProvider
NewTypedConfigProvider creates a ConfigProvider using a selective type option (of type string) for choosing among multiple variants given as nested providers. The provider is selected if the option for this type or the plain option has been given on the command line.
type ValueMapOption ¶
type ValueMapOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*ValueMapOption) AddFlags ¶
func (o *ValueMapOption) AddFlags(fs *pflag.FlagSet)
func (*ValueMapOption) Value ¶
func (o *ValueMapOption) Value() interface{}
type ValueMapOptionType ¶
type ValueMapOptionType struct {
TypeOptionBase
}
func (*ValueMapOptionType) Create ¶
func (s *ValueMapOptionType) Create() Option
func (*ValueMapOptionType) Equal ¶
func (s *ValueMapOptionType) Equal(optionType OptionType) bool
type ValueMapYAMLOption ¶
type ValueMapYAMLOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*ValueMapYAMLOption) AddFlags ¶
func (o *ValueMapYAMLOption) AddFlags(fs *pflag.FlagSet)
func (*ValueMapYAMLOption) Value ¶
func (o *ValueMapYAMLOption) Value() interface{}
type ValueMapYAMLOptionType ¶
type ValueMapYAMLOptionType struct {
TypeOptionBase
}
func (*ValueMapYAMLOptionType) Create ¶
func (s *ValueMapYAMLOptionType) Create() Option
func (*ValueMapYAMLOptionType) Equal ¶
func (s *ValueMapYAMLOptionType) Equal(optionType OptionType) bool
type YAMLOption ¶
type YAMLOption struct {
OptionBase
// contains filtered or unexported fields
}
func (*YAMLOption) AddFlags ¶
func (o *YAMLOption) AddFlags(fs *pflag.FlagSet)
func (*YAMLOption) Value ¶
func (o *YAMLOption) Value() interface{}
type YAMLOptionType ¶
type YAMLOptionType struct {
TypeOptionBase
}
func (*YAMLOptionType) Create ¶
func (s *YAMLOptionType) Create() Option
func (*YAMLOptionType) Equal ¶
func (s *YAMLOptionType) Equal(optionType OptionType) bool
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package scheme uses the flagsets.OptionSet handling from package flagsets to handle a command line option based configuration of instances of dynamically registered Type declarations.
|
Package scheme uses the flagsets.OptionSet handling from package flagsets to handle a command line option based configuration of instances of dynamically registered Type declarations. |