Skip to content

ScottKGregory/mamba

Repository files navigation

🐍 Mamba

Because who doesn't need more snakes?

Build Status Go Report Card GitHub go.mod Go version GitHub

What is Mamba?

Mamba is a utility designed to make working with the combination of cobra and viper require less boilerplate setup.

Quick start

  1. Install Mamba
go get github.com/scottkgregory/mamba
  1. 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!"`
}
  1. Call Mamba in the init of your Cobra command
  mamba.Bind(Config{}, rootCmd)
  1. Run your program with the --help flag to view your bound flags

  2. Go forth and use your config! From this point on your config values will all be available via Viper

Examples

Configuration

Options can be supplied to mamba.Bind to modify the way in which Mamba operates.

mamba.Bind(AppConfig{}, rootCmd, &mamba.Options{ Persistent: true })

About

An automatic configurator for Viper and Cobra

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages