A combination command-line flag and configuration file library for Go.
// define your flags.
var procs int
flag.IntVar(&procs, "procs", runtime.NumCPU(), "GOMAXPROCS")
// set flags from configuration before parse command-line flags.
if args, err := conflag.ArgsFrom("/path/to/config.toml"); err == nil {
flag.CommandLine.Parse(args)
}
// parse command-line flags.
flag.Parse()
and you create /path/to/config.toml
procs = 2
and run your app without option, procs
flag will be set in 2
that is defined at configration file.
A priority of flag is
command-line flag
> configration file
> flag default value
In the above case,
run | procs |
---|---|
myapp -procs 3 | 3 |
myapp (with config-file) | 2 |
myapp (without config-file) | runtime.NumCPU() (default of flag) |
You can specify positions
arguments to ArgsFrom
function.
[options]
flag = "value"
[other settings]
hoge = "fuga"
// parse configration only under the options section.
conflag.ArgsFrom("/path/to/config.toml", "options")
- Combine command-line flag and configuration file.
- Specify configration section.
- Support TOML configuration file.
- Support JSON configuration file.
$ go get github.com/monochromegane/conflag
- Fork it
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
go test ./...
command and confirm that it passes - Run
gofmt -s
- Create new Pull Request