Documentation
¶
Overview ¶
Package ptypes contains a variety of types of common utility amongst the other packages in the param.mod module
Index ¶
- type AValCache
- type Aliases
- func (a Aliases[T]) AliasVal(name T) []T
- func (a Aliases[T]) AllowedValuesAliasMap() Aliases[string]
- func (a Aliases[T]) Check(av AllowedVals[T]) error
- func (a Aliases[T]) CheckMapLengths(minLen, maxLen int) error
- func (a Aliases[T]) IsAnAlias(val string) bool
- func (a Aliases[T]) Keys() ([]string, int)
- func (a Aliases[T]) String() string
- type AllowedVals
- type AllowedValuesAliasMapper
- type AllowedValuesMapper
- type OptFunc
- type ValDescriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AValCache ¶
AValCache is a cache of allowed value descriptions and where they were first shown.
type Aliases ¶
type Aliases[T ~string] map[T][]T
Aliases - this maps strings to lists of strings. It is expected that the keys are not in the set of allowed values and the entries in the associated value are allowed.
It can be used as a mixin type that can be embedded in a Setter to provide alternative names for allowed values or to provide several names in one.
It is recommended that you should use string constants for setting the aliases and the entries in the slice of values they correspond to. This will avoid possible errors.
The advantages of const values are:
- typos become compilation errors rather than silently failing.
- the name of the constant value can distinguish between the string value and it's meaning as a semantic element representing a flag used to choose program behaviour.
- the name that you give the const value can distinguish between identical strings and show which of various flags with the same string value you actually mean.
func (Aliases[T]) AliasVal ¶
func (a Aliases[T]) AliasVal(name T) []T
AliasVal returns a copy of the value of the alias
func (Aliases[T]) AllowedValuesAliasMap ¶
AllowedValuesAliasMap returns a copy of the map of aliases. This will be used by the standard help package to generate a list of allowed values.
func (Aliases[T]) Check ¶
func (a Aliases[T]) Check(av AllowedVals[T]) error
Check returns a nil error if the map is "good" or an error with an explanation of the problem otherwise.
A map is "good" if each key does not exist in the AllowedVals but each entry in the associated list is in the AllowedVals. Also, an empty alias is not allowed.
func (Aliases[T]) CheckMapLengths ¶
CheckMapLengths returns a non-nil error if any of the alias entries has an associated entry with a length less then minLen or greater than maxLen. It returns nil if all the entries are in the right length range. It will panic unless 0 < minLen <= maxLen.
func (Aliases[T]) IsAnAlias ¶
IsAnAlias returns true if the passed value is a key in the aliases map
type AllowedVals ¶
AllowedVals - this maps allowed values for an enumerated parameter to explanatory text. It forms part of the usage documentation of the program. It is also used to validate a supplied parameter.
It can be used as a mixin type that can be embedded in a Setter to provide a restricted set of allowed values.
It is recommended that you should use string constants for setting the map entries.
The advantages of const values are:
- typos become compilation errors rather than silently failing.
- the name of the constant value can distinguish between the string value and it's meaning as a semantic element representing a flag used to choose program behaviour.
- the name that you give the const value can distinguish between identical strings and show which of various flags with the same string value you actually mean.
func (AllowedVals[T]) AllowedValuesMap ¶
func (av AllowedVals[T]) AllowedValuesMap() AllowedVals[string]
AllowedValuesMap returns a copy of the map of allowed values. This will be used by the standard help package to generate a list of allowed values.
func (AllowedVals[T]) Check ¶
func (av AllowedVals[T]) Check() error
Check returns a nil error if the map is "good" or an error with an explanation of the problem otherwise.
A map is "good" if it has more than one entry. A set of allowed values with one or fewer entries is obviously a mistake: if no entries are valid then the parameter can never be set correctly and if it only has a single entry then the current (initial) value is the only allowed value and so there is no need for a parameter as no alternative can ever be allowed.
func (AllowedVals[T]) Keys ¶
func (av AllowedVals[T]) Keys() ([]string, int)
Keys returns an unsorted list of keys to the AllowedVals map and the length of the longest key.
func (AllowedVals[T]) String ¶
func (av AllowedVals[T]) String() string
String returns a string documenting the entries in the map - each entry is on a separate line
func (AllowedVals[T]) ValueAllowed ¶
func (av AllowedVals[T]) ValueAllowed(val string) bool
ValueAllowed returns true if the passed value is a key in the allowed values map
type AllowedValuesAliasMapper ¶
AllowedValuesAliasMapper is the interface to be satisfied by a type having aliases
type AllowedValuesMapper ¶
type AllowedValuesMapper interface {
AllowedValuesMap() AllowedVals[string]
}
AllowedValuesMapper is the interface to be satisfied by a type having a map of allowed values.
type OptFunc ¶
OptFunc represents an option function - something taking a pointer to a value with the intention of transforming it in some way and returning an error if the transformation failed. These functions can be passed as variadic parameters to other functions (typically, but not necessarily, a function that creates an initial value - a constructor)
type ValDescriber ¶
type ValDescriber interface {
ValDescribe() string
}
ValDescriber is an interface for a function which can be added as a method on an existing Setter and if it is present its return value will be used to describe the parameter value to be supplied. It only makes sense to provide such a method if the parameter can take a value.