Documentation ¶
Overview ¶
Package pflag loads configuration from flags defined by spf13/pflag.
PFlag loads flags in pflag.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 Option ¶
type Option func(*options)
Option configures the a PFlag with specific options.
func WithFlagSet ¶
WithFlagSet provides the pflag.FlagSet that loads configuration from.
The default flag set is pflag.CommandLine plus 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.
type PFlag ¶
type PFlag struct {
// contains filtered or unexported fields
}
PFlag is a Provider that loads configuration from flags defined by spf13/pflag.
To create a new PFlag, call New.