flagsets

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NopConfigHandler = NewNopConfigHandler()

NopConfigHandler is a dummy config handler doing nothing.

Functions

func AddFieldByMappedOption

func AddFieldByMappedOption(opts OptionValueProvider, oname string, config Config, mapper func(interface{}) (interface{}, error), names ...string) error

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 AddGroups

func AddGroups(list []string, groups ...string) []string

func AddPrefix

func AddPrefix(prefix string, values ...string) []string

func FormatConfigOptions

func FormatConfigOptions(handler ConfigOptionTypeSetHandler) string

func GetField

func GetField(config Config, names ...string) (interface{}, error)

func OptionSpec

func OptionSpec(otype ConfigOptionType, args ...string) _OptionSpec

func OptionString

func OptionString(option ConfigOptionType) string

func OptionStrings

func OptionStrings(types ...ConfigOptionType) []string

func ParseOptionsFor

func ParseOptionsFor(flags *pflag.FlagSet, specs ..._OptionSpec) error

func SetField

func SetField(config Config, value interface{}, names ...string) error

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 ConfigOptionType) 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 ConfigOptionType) bool

type Config

type Config = map[string]interface{}

Config is a generic structured config stored in a string map.

type ConfigAdder

type ConfigAdder func(options ConfigOptions, config Config) error

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 ConfigOptions, config Config) error

type ConfigHandler

type ConfigHandler interface {
	ApplyConfig(options ConfigOptions, config Config) error
}

ConfigHandler describes the ConfigAdder functionality.

func NewNopConfigHandler

func NewNopConfigHandler() ConfigHandler

type ConfigOptionType

type ConfigOptionType interface {
	GetName() string
	GetDescription() string

	Create() Option

	Equal(optionType ConfigOptionType) bool
}

func NewBoolOptionType

func NewBoolOptionType(name string, description string) ConfigOptionType

func NewBytesOptionType

func NewBytesOptionType(name string, description string) ConfigOptionType

func NewIdentityPathOptionType added in v0.15.0

func NewIdentityPathOptionType(name string, description string) ConfigOptionType

func NewIntOptionType

func NewIntOptionType(name string, description string) ConfigOptionType

func NewPathArrayOptionType

func NewPathArrayOptionType(name string, description string) ConfigOptionType

func NewPathOptionType

func NewPathOptionType(name string, description string) ConfigOptionType

func NewStringArrayOptionType

func NewStringArrayOptionType(name string, description string) ConfigOptionType

func NewStringMapOptionType

func NewStringMapOptionType(name string, description string) ConfigOptionType

func NewStringOptionType

func NewStringOptionType(name string, description string) ConfigOptionType

func NewStringSliceMapColonOptionType

func NewStringSliceMapColonOptionType(name string, description string) ConfigOptionType

func NewStringSliceMapOptionType

func NewStringSliceMapOptionType(name string, description string) ConfigOptionType

func NewValueMapOptionType

func NewValueMapOptionType(name string, description string) ConfigOptionType

func NewValueMapYAMLOptionType

func NewValueMapYAMLOptionType(name string, description string) ConfigOptionType

func NewYAMLOptionType

func NewYAMLOptionType(name string, description string) ConfigOptionType

type ConfigOptionTypeSet

type ConfigOptionTypeSet interface {
	AddGroups(groups ...string)

	GetName() string

	Size() int
	OptionTypes() []ConfigOptionType
	OptionTypeNames() []string
	SharedOptionTypes() []ConfigOptionType

	HasOptionType(name string) bool
	HasSharedOptionType(name string) bool

	GetSharedOptionType(name string) ConfigOptionType
	GetOptionType(name string) ConfigOptionType
	GetTypeSet(name string) ConfigOptionTypeSet
	OptionTypeSets() []ConfigOptionTypeSet

	AddOptionType(ConfigOptionType) error
	AddTypeSet(ConfigOptionTypeSet) error
	AddAll(o ConfigOptionTypeSet) (duplicated ConfigOptionTypeSet, err error)

	Close(funcs ...func([]ConfigOptionType) error) error

	CreateOptions() ConfigOptions
	AddGroupsToOption(o Option)
}

func NewConfigOptionTypeSet

func NewConfigOptionTypeSet(name string, types ...ConfigOptionType) ConfigOptionTypeSet

type ConfigOptionTypeSetHandler

type ConfigOptionTypeSetHandler interface {
	ConfigOptionTypeSet
	ConfigHandler
}

ConfigOptionTypeSetHandler describes a ConfigOptionTypeSet, which also provides the possibility to provide config.

func NewConfigOptionTypeSetHandler

func NewConfigOptionTypeSetHandler(name string, adder ConfigAdder, types ...ConfigOptionType) ConfigOptionTypeSetHandler

NewConfigOptionTypeSetHandler creates a new ConfigOptionTypeSetHandler.

type ConfigOptions

type ConfigOptions interface {
	AddTypeSetGroupsToOptions(set ConfigOptionTypeSet)

	AddFlags(fs *pflag.FlagSet)

	Options() []Option
	Names() []string

	Size() int
	HasOption(name string) bool

	Check(set ConfigOptionTypeSet, desc string) error
	GetValue(name string) (interface{}, bool)
	Changed(names ...string) bool

	FilterBy(Filter) ConfigOptions
}

ConfigOptions 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 NewOptions(opts []Option) ConfigOptions

func NewOptionsByList

func NewOptionsByList(opts ...Option) ConfigOptions

type ConfigProvider

type ConfigProvider interface {
	CreateOptions() ConfigOptions
	GetConfigFor(opts ConfigOptions) (Config, error)
}

type ConfigTypeOptionSetConfigProvider

type ConfigTypeOptionSetConfigProvider interface {
	ConfigProvider
	ConfigOptionTypeSet

	GetPlainOptionType() ConfigOptionType
	GetTypeOptionType() ConfigOptionType

	IsExplicitlySelected(opts ConfigOptions) bool
}

func NewPlainConfigProvider

func NewPlainConfigProvider(name string, adder ConfigAdder, types ...ConfigOptionType) ConfigTypeOptionSetConfigProvider

func NewTypedConfigProvider

func NewTypedConfigProvider(name string, desc, typeOption string, acceptUnknown ...bool) ConfigTypeOptionSetConfigProvider

func NewTypedConfigProviderBase

func NewTypedConfigProviderBase(name string, desc string, prov TypeNameProvider, acceptUnknown bool, types ...ConfigOptionType) ConfigTypeOptionSetConfigProvider

type ExplicitlyTypedConfigTypeOptionSetConfigProvider

type ExplicitlyTypedConfigTypeOptionSetConfigProvider interface {
	ConfigTypeOptionSetConfigProvider
	SetTypeName(n string)
}

func NewExplicitlyTypedConfigProvider

func NewExplicitlyTypedConfigProvider(name string, desc string, acceptUnknown ...bool) ExplicitlyTypedConfigTypeOptionSetConfigProvider

type Filter

type Filter func(name string) bool

func And

func And(fs ...Filter) Filter

func Changed

func Changed(opts ConfigOptions) Filter

func Not

func Not(f Filter) Filter

func Or

func Or(fs ...Filter) Filter

type IdentityPathOption added in v0.15.0

type IdentityPathOption struct {
	OptionBase
	// contains filtered or unexported fields
}

func (*IdentityPathOption) AddFlags added in v0.15.0

func (o *IdentityPathOption) AddFlags(fs *pflag.FlagSet)

func (*IdentityPathOption) Value added in v0.15.0

func (o *IdentityPathOption) Value() interface{}

type IdentityPathOptionType added in v0.15.0

type IdentityPathOptionType struct {
	TypeOptionBase
}

func (*IdentityPathOptionType) Create added in v0.15.0

func (s *IdentityPathOptionType) Create() Option

func (*IdentityPathOptionType) Equal added in v0.15.0

func (s *IdentityPathOptionType) Equal(optionType ConfigOptionType) bool

type IntOption

type IntOption struct {
	OptionBase
	// contains filtered or unexported fields
}

func (*IntOption) AddFlags

func (o *IntOption) AddFlags(fs *pflag.FlagSet)

func (*IntOption) Value

func (o *IntOption) Value() interface{}

type IntOptionType

type IntOptionType struct {
	TypeOptionBase
}

func (*IntOptionType) Create

func (s *IntOptionType) Create() Option

func (*IntOptionType) Equal

func (s *IntOptionType) Equal(optionType ConfigOptionType) bool

type NameProvider

type NameProvider interface {
	GetName() string
}

type Option

type Option interface {
	GetName() string
	AddFlags(fs *pflag.FlagSet)
	Value() interface{}

	Changed() bool
	AddGroups(groups ...string)
}

type OptionBase

type OptionBase struct {
	// contains filtered or unexported fields
}

func NewOptionBase

func NewOptionBase(otyp ConfigOptionType) 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) GetName

func (b *OptionBase) GetName() string

func (*OptionBase) TweakFlag

func (b *OptionBase) TweakFlag(f *pflag.Flag)

func (*OptionBase) Type

func (b *OptionBase) Type() ConfigOptionType

type OptionName

type OptionName string

func (OptionName) GetName

func (n OptionName) GetName() string

type OptionValueProvider

type OptionValueProvider interface {
	GetValue(name string) (interface{}, bool)
}

OptionValueProvider provides values for named options.

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 ConfigOptionType) 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 ConfigOptionType) 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 ConfigOptionType) 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 ConfigOptionType) 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 ConfigOptionType) 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 (*StringSliceMapColonOptionType) Equal

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 ConfigOptionType) bool

type TypeNameProvider

type TypeNameProvider func(opts ConfigOptions) (string, error)

func TypeNameProviderFromOptions

func TypeNameProviderFromOptions(name string) TypeNameProvider

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 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 ConfigOptionType) 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 ConfigOptionType) 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 ConfigOptionType) bool

Directories

Path Synopsis
Package flagsetscheme provides a runtime.TypeScheme with support for command line option sets for the described object types.
Package flagsetscheme provides a runtime.TypeScheme with support for command line option sets for the described object types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL