Package flagconf wraps the standard golang package flag. It intercepts it and preloads configuration values from local files (home-directory, /etc) and environment variables in order to retrieve default values. The resulting order of flag loading is:
- in-code values (defaults provided in flagset, which is usually defined in the init function)
- local file list (default is "~/.falgconf/.yaml")
- environment variables
- command line arguments
package main
import (
"github.com/sebkl/flagconf"
"flag"
)
var val *string
func init() {
val = flag.String("val","defaultvalue","This is my application flag."
}
func main() {
// The file "~/.flagconf/MYAPP.yml" and
// all environemnt variables starting with "MYAPP"
// are being evaluated for a flag value named "val"
// If found the default value "defaultvalue" is overwritten.
flagconf.Parse("MYAPP")
/* ... code ... */
}
- Json encoded configuration files instead of yaml.
- Provide an ordered list of files to look for flag values by the FileList function.
flag | Description |
---|---|
flagconfConfirm |
Show all flag configs before execution. |
flagconfFile |
Explicitly define a file to read flag configs from. |
Please find documentation at godoc.org/github.com/sebkl/flagconf.
Pleas feel free to send in Pull request. I want to make this a more comprehensive library for dealing with command line flags.