CLI configuration via flags and environment variables.
The interface follows closely the flag/pflag packages.
package main
import "github.com/goph/conf"
func main() {
// Define environment variables and flags using conf.String(), Bool(), Int(), etc.
var intValue *int = conf.Int("int", 1234, "help message for int")
// If you like, you can bind the environment variable and the flag to a variable using the Var() functions.
var intVar int
conf.IntVar(&intVar, "int", 1234, "help message for int")
// Or you can create custom variables that satisfy the Value interface (with pointer receivers)
// and couple them to variable parsing.
//
// For such environment variables/flags, the default value is just the initial value of the variable.
var intVal conf.Value
conf.Var(&intVal, "int", "help message for int")
// If you prefer only environment variables or flags as a source for certain values,
// you can use the above methods with the "E" and "F" suffix.
intValue = conf.IntF("int", 1234, "help message for int")
intValue = conf.IntE("int", 1234, "help message for int")
// After all variables are defined.
conf.Parse()
}
dep is required to install dependencies:
$ make dep # dep ensure
When all coding and testing is done, please run the test suite:
$ make test # go test
For linting we use GolangCI.
$ make lint # golangci-lint run
You can run the whole suite with:
$ make check
The MIT License (MIT). Please see License File for more information.