Because who doesn't need more snakes?
Mamba is a utility designed to make working with the combination of cobra and viper require less boilerplate setup.
- Install Mamba
go get github.com/scottkgregory/mamba
- Annotation your config struct using the config tag in the form
config:"default, description, persistent, shorthand"
. Arrays, slices, and maps allow for setting default values via json. Any of these values can be omitted.
type Config struct {
Root string `config:"defaultRoot,The root directory to do a thing with"`
Number int `config:"12,A number to use for a thing"`
Snakes []string `config:"[\"adder\"],A list of snakes. Hsssss!"`
}
- Call Mamba in the init of your Cobra command
mamba.Bind(Config{}, rootCmd)
-
Run your program with the
--help
flag to view your bound flags -
Go forth and use your config! From this point on your config values will all be available via Viper
Options can be supplied to mamba.Bind
to modify the way in which Mamba operates.
mamba.Bind(AppConfig{}, rootCmd, &mamba.Options{ Persistent: true })