Documentation
¶
Overview ¶
Package flagfile provides disk serialization and parsing extensions to the builtin flags library
If you use flagfile.Load() instead of flag.Parse() in your main method, not only can you continue to use flags as you always have, but you can specify a --flagfile option and store your flags in multiple config files on disk.
flagfile provides the following additional config options:
--flagfile: a comma-separated list of paths to load --flagout: writes all configured flag settings to this path after load
Precedence ¶
A flag set on the command line has the highest precedence. A flag set in a flagfile has the next highest. The default value has the lowest.
Flagfile format ¶
Flagfiles are simple text files containing lines of the form `key = val` with optional section headers. Lines may be prefixed with a `#` to comment them out. Example:
some.flag = 20 # some.other.flag = 50 flag3 = 10m flag4 = a string value [section1] flag1 = 30 flag2 = 40 [section2] flag1 = 50 flag2 = true
If a section is specified in square braces, all of the following flags up until the next section are effectively prefixed with the section name followed by a period.
See github.com/spacemonkeygo/flagfile/parser for more information on the file format.
Index ¶
- func Alias(new_flag_name, old_flag_name string)
- func Dump(out io.Writer) error
- func DumpToPath(path string) error
- func FullUsage()
- func IsActivelySet(flag_name string) bool
- func IsAlias(flag_name string) bool
- func Load(opts ...Option)
- func Setup(prefix string, x interface{})
- func ShortUsage()
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alias ¶
func Alias(new_flag_name, old_flag_name string)
Alias links two flag names together. If you have a particular flag that needs to be configured by one flag name in one deployment and another name in another deployment, Alias lets you link the two flag names together. It is an error to configure both aliases with differing values.
func Dump ¶
Dump will write all configured flags to the given io.Writer in the flagfile serialization format for later parsing.
func DumpToPath ¶
DumpToPath simply calls Dump on a new filehandle (O_CREATE|O_TRUNC) for the given path
func IsActivelySet ¶
IsActivelySet returns whether or not the user configured the given flag. The value is false if the flag was not set by commandline or flagfile.
func IsAlias ¶
IsAlias returns true if the flag name is just an alias. False if the flag was defined normally.
func Load ¶
func Load(opts ...Option)
Load is the flagfile equivalent/replacement for flag.Parse() Call once at program start.
func Setup ¶
func Setup(prefix string, x interface{})
Setup is a deprecated wrapper around flagfile/utils.Setup http://godoc.org/github.com/spacemonkeygo/flagfile/utils#Setup
func ShortUsage ¶
func ShortUsage()
ShortUsage only outputs to stderr flags without "." and withholds some system flags.
Types ¶
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
func Flagfile ¶
Flagfile tells Load to find default values from the flagfile at path (which will be overridden by user-provided values from arguments, if provided).
func FullUsageFunc ¶
func FullUsageFunc(fn func()) Option
FullUsageFunc specifies what method to run when '--help-all' is found.
func IgnoreUnknownFlags ¶
func IgnoreUnknownFlags() Option
IgnoreUnknownFlags tells Load to skip loading values for non-existent flags
func OptFlagfile ¶
OptFlagfile is like Flagfile but does not fail if the path doesn't exist.
func ShortUsageFunc ¶
func ShortUsageFunc(fn func()) Option
ShortUsageFunc specifies what method to run when '-h' or '--help' are found.
Directories
¶
Path | Synopsis |
---|---|
Package parser provides parsing and serializing routines for the flagfile on-disk format
|
Package parser provides parsing and serializing routines for the flagfile on-disk format |
Package utils provides a collection of nice flag/flagfile helpers without requiring someone to actually use flagfile.Load() over flag.Parse()
|
Package utils provides a collection of nice flag/flagfile helpers without requiring someone to actually use flagfile.Load() over flag.Parse() |