Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse the flags in the flag set from the provided (presumably commandline) args. Additional options may be provided to parse from a config file and/or environment variables in that priority order.
func PlainParser ¶
PlainParser is a parser for config files in an extremely simple format. Each line is tokenized as a single key/value pair. The first whitespace-delimited token in the line is interpreted as the flag name, and all remaining tokens are interpreted as the value. Any leading hyphens on the flag name are ignored.
Types ¶
type ConfigFileParser ¶
ConfigFileParser interprets the config file represented by the reader and calls the set function for each parsed flag pair.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context contains private fields used during parsing.
type Option ¶
type Option func(*Context)
Option controls some aspect of parse behavior.
func WithConfigFile ¶
WithConfigFile tells parse to read the provided filename as a config file. Requires WithConfigFileParser, and overrides WithConfigFileFlag.
func WithConfigFileFlag ¶
WithConfigFileFlag tells parse to treat the flag with the given name as a config file. Requires WithConfigFileParser, and is overridden by WithConfigFile.
func WithConfigFileParser ¶
func WithConfigFileParser(p ConfigFileParser) Option
WithConfigFileParser tells parse how to interpret the config file provided via WithConfigFile or WithConfigFileFlag.
func WithEnvVarPrefix ¶
WithEnvVarPrefix tells parse to look in the environment for variables with the given prefix. Flag names are converted to environment variables by capitalizing them, and replacing separator characters like periods or hyphens with underscores. Additionally, if the environment variable's value contains commas, each comma-delimited token is treated as a separate instance of the associated flag name.