flagfile: github.com/spacemonkeygo/flagfile Index | Files | Directories

package flagfile

import "github.com/spacemonkeygo/flagfile"

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


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

flag1 = 30
flag2 = 40

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.


Package Files

aliases.go doc.go load.go out.go setup.go usage.go

func Alias Uses

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 Uses

func Dump(out io.Writer) error

Dump will write all configured flags to the given io.Writer in the flagfile serialization format for later parsing.

func DumpToPath Uses

func DumpToPath(path string) error

DumpToPath simply calls Dump on a new filehandle (O_CREATE|O_TRUNC) for the given path

func FullUsage Uses

func FullUsage()

FullUsage outputs full usage information to stderr. All flags.

func IsActivelySet Uses

func IsActivelySet(flag_name string) bool

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 Uses

func IsAlias(flag_name string) bool

IsAlias returns true if the flag name is just an alias. False if the flag was defined normally.

func Load Uses

func Load(opts ...Option)

Load is the flagfile equivalent/replacement for flag.Parse() Call once at program start.

func Setup Uses

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 Uses

func ShortUsage()

ShortUsage only outputs to stderr flags without "." and withholds some system flags.

type Option Uses

type Option struct {
    // contains filtered or unexported fields

func Flagfile Uses

func Flagfile(path string) Option

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 Uses

func FullUsageFunc(fn func()) Option

FullUsageFunc specifies what method to run when '--help-all' is found.

func IgnoreUnknownFlags Uses

func IgnoreUnknownFlags() Option

IgnoreUnknownFlags tells Load to skip loading values for non-existent flags

func OptFlagfile Uses

func OptFlagfile(path string) Option

OptFlagfile is like Flagfile but does not fail if the path doesn't exist.

func ShortUsageFunc Uses

func ShortUsageFunc(fn func()) Option

ShortUsageFunc specifies what method to run when '-h' or '--help' are found.

func SkipArgs Uses

func SkipArgs() Option

SkipArgs will tell Load to not call flag.Parse and otherwise avoid looking at process arguments


parserPackage parser provides parsing and serializing routines for the flagfile on-disk format
utilsPackage utils provides a collection of nice flag/flagfile helpers without requiring someone to actually use flagfile.Load() over flag.Parse()

Package flagfile imports 9 packages (graph) and is imported by 4 packages. Updated 2018-04-29. Refresh now. Tools for package owners.