Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoSourceProvidedValue = errors.New("no source provided a value")
Functions ¶
func ParseTextUnmarshaler ¶
func ParseTextUnmarshaler[T any, P interface { *T encoding.TextUnmarshaler }](s string) (T, error)
Types ¶
type DefaultSource ¶
func StaticDefault ¶
func StaticDefault(v string) DefaultSource
func (DefaultSource) Describe ¶
func (d DefaultSource) Describe(key string) string
type FallbackSource ¶
type FallbackSource struct {
Source
// Stored marks a value a person saved earlier, such as in a profile, so that the environment
// overriding it with another value is warned of. Resolving looks it up only then, so it must
// not prompt.
Stored bool
}
FallbackSource ranks the wrapped source below the environment, see Sources.ResolveSetting.
type FrontendSource ¶
type FrontendSource struct {
Source
}
FrontendSource ranks the wrapped source above the environment, see Sources.ResolveSetting.
type LookupSource ¶
type LookupSource struct {
MatchingKey string
Description string
Func func(ctx context.Context) (string, error)
}
func (LookupSource) Describe ¶
func (s LookupSource) Describe(key string) string
type Setting ¶
type Setting[T any] struct { Env EnvKey // Short is plain text for a cobra flag, Long is Markdown for the Terraform provider's schema. // Both state facts about the setting rather than about a front end, so neither says "flag", // "block" or "attribute". Short func(envKey string) string Long func(envKey string) string Default DefaultSource // Parse always receives a non-empty string: Resolve trims what a source returned and skips // that source when nothing is left. Parse func(v string) (T, error) }
Setting declares one input. Its environment variable key is also its identity, so every setting can be controlled through the environment and there is no second identifier to hold in step.
func (Setting[T]) HelpMarkdown ¶
type Source ¶
type Source interface {
// Lookup returns an empty string and no error when it carries no value. An error stops the
// whole resolution, so return one only for a condition no other source can make up for.
Lookup(ctx context.Context, key string) (string, error)
// Describe names this source to a person, so that a failed resolution can list what to set.
Describe(key string) string
}
type Sources ¶
type Sources []Source
func (Sources) ResolveSetting ¶
func (sources Sources) ResolveSetting[T any](ctx context.Context, setting Setting[T], extraSources ...Source) (value T, err error)
ResolveSetting takes the value from the first source that carries one, in this order: FrontendSource, any other source, the environment, FallbackSource, the setting's default. Two sources of the same kind keep the order they were given in. It returns ErrNoSourceProvidedValue when every source stayed empty.