package module
Version: v0.0.0-...-0d75033 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2018 License: Apache-2.0 Imports: 9 Imported by: 12


flagfile Build Status

Please see http://godoc.org/github.com/spacemonkeygo/flagfile for info


Copyright (C) 2014 Space Monkey, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



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.



This section is empty.


This section is empty.


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

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

func DumpToPath(path string) error

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

func FullUsage

func FullUsage()

FullUsage outputs full usage information to stderr. All flags.

func IsActivelySet

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

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

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.


type Option

type Option struct {
	// contains filtered or unexported fields

func Flagfile

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

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

func OptFlagfile(path string) Option

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.

func SkipArgs

func SkipArgs() Option

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


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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL