Documentation ¶
Overview ¶
Package flag loads configuration from flags defined by flag.
Flag loads flags in flag.CommandLine whose names starts with the given prefix and returns them as a nested map[string]any. The unchanged flags with zero default value are skipped to avoid overriding values set by other loader.
It splits the names by delimiter. For example, with the default delimiter ".", the flag `parent.child.key="1"` is loaded as `{parent: {child: {key: "1"}}}`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
Flag is a Provider that loads configuration from flags.
To create a new Flag, call New.
type Option ¶
type Option func(*options)
Option configures the a Flag with specific options.
func WithFlagSet ¶
WithFlagSet provides the flag.FlagSet that loads configuration from.
The default flag set is flag.CommandLine.
func WithNameSplitter ¶ added in v0.5.0
WithNameSplitter provides the function used to split flag names into nested keys. If it returns an nil/[]string{}/[]string{""}, the variable will be ignored.
For example, with the default splitter, an flag name like "parent.child.key" would be split into "parent", "child", and "key".
func WithPrefix ¶
WithPrefix provides the prefix used when loading flags. Only flags with names that start with the prefix will be loaded.
For example, if the prefix is "server", only flags whose names start with "server" will be loaded. By default, it has no prefix which loads all flags.