All Projects → erizocosmico → flagga

erizocosmico / flagga

Licence: MIT License
An extensible Go library for handling program configuration using flags.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to flagga

sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-28.57%)
Mutual labels:  configuration, environment-variables
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (+17.86%)
Mutual labels:  configuration, environment-variables
envflag
Simple environment-variables extension to Golang flag.
Stars: ✭ 21 (-25%)
Mutual labels:  environment-variables, flags
Environ Config
Python Application Configuration With Environment Variables
Stars: ✭ 210 (+650%)
Mutual labels:  configuration, environment-variables
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (+207.14%)
Mutual labels:  configuration, environment-variables
Cleanenv
✨Clean and minimalistic environment configuration reader for Golang
Stars: ✭ 245 (+775%)
Mutual labels:  configuration, environment-variables
paerser
No description or website provided.
Stars: ✭ 38 (+35.71%)
Mutual labels:  configuration, environment-variables
Fig
A minimalist Go configuration library
Stars: ✭ 142 (+407.14%)
Mutual labels:  configuration, environment-variables
envkey-python
EnvKey's python library. Protect API keys and credentials. Keep configuration in sync.
Stars: ✭ 24 (-14.29%)
Mutual labels:  configuration, environment-variables
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-28.57%)
Mutual labels:  configuration, environment-variables
Config
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP
Stars: ✭ 203 (+625%)
Mutual labels:  configuration, environment-variables
arkenv
Type-safe Kotlin configuration by delegates
Stars: ✭ 15 (-46.43%)
Mutual labels:  configuration, environment-variables
Go Flagz
Dynamic flag management for Go.
Stars: ✭ 191 (+582.14%)
Mutual labels:  configuration, flags
Konfig
Simple config properties API for Kotlin
Stars: ✭ 249 (+789.29%)
Mutual labels:  configuration, environment-variables
Aconfig
Simple, useful and opinionated config loader.
Stars: ✭ 187 (+567.86%)
Mutual labels:  configuration, environment-variables
read-env
🔧 Transform environment variables into JSON object with sanitized values.
Stars: ✭ 60 (+114.29%)
Mutual labels:  configuration, environment-variables
Config
A lightweight yet powerful config package for Go projects
Stars: ✭ 126 (+350%)
Mutual labels:  configuration, environment-variables
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+6525%)
Mutual labels:  configuration, environment-variables
dart environment config
Environment specific config generator for Dart and Flutter applications during CI/CD builds
Stars: ✭ 87 (+210.71%)
Mutual labels:  configuration, environment-variables
ngx-env
Easily inject environment variables into your Angular applications
Stars: ✭ 73 (+160.71%)
Mutual labels:  configuration, environment-variables

flagga GoDoc Build Status codecov Go Report Card License: MIT

flagga is an extensible Go library for handling program configuration using (but not limited to) command line arguments, environment variables and JSON.

This idea and API come from Peter Bourgon's Go for Industrial Programming talk at Gophercon Iceland 2018.

It should work as a drop-in replacement for the standard library flag package. The only difference is the fact that NewFlagSet and Init accept a second string for the description.

Goals

  • Be able to configure a program with different sources that have different priorities.
  • Be extensible so anyone can extend the API to provide different sources to get their configuration from (yaml, toml, database?, ...).
  • Be a drop-in replacement for the Go standard flag package with extra features.
  • Have no third-party dependencies.

Install

go get github.com/erizocosmico/flagga

Or use your preferred dependency manager such as dep or vgo.

Usage

var fs flagga.FlagSet

db := fs.String("db", defaultDBURI, "database connection string", flagga.Env("DBURI"))
users := fs.StringList("users", nil, "list of allowed users", flagga.JSON("users"))

err := fs.Parse(os.Args[1:], flagga.JSONVia("config.json"), flagga.EnvPrefix("MYAPP_"))
if err != nil {
    // handle err
}

fmt.Println(*db) // Outputs: "user@localhost:1234/foo"
fmt.Println(strings.Join(*users, ", ")) // Outputs: "jane, joe, alice"

To get the previous results we can invoke the program in the following ways:

echo '{"users":["jane", "joe", "alice"]}' > config.json
./myprogram -db=user@localhost:1234/foo -users=jane -users=joe -users=alice
MYAPP_DBURI=user@localhost:1234/foo ./myprogram

Priority of sources

CLI flags always have priority over environment variables or JSON keys. If a flag is provided using the command line flags, no other sources will be checked for that variable.

The rest of the priorities depend of the order in which the sources are passed to the Parse method. For example, fs.Parse(os.Args, flagga.EnvPrefix("FOO_"), flagga.JSONVia("cfg")) gives more priority to environment variables than to the JSON configuration.

Available Extractors

  • Env: from environment variable sources.
  • JSON: from JSON sources.

YAML and TOML extractors are available in the flaggax repository.

Available Sources

  • EnvPrefix: provides all environment variables matching the given prefix.
  • JSONVia: provides the content of the JSON in the given file.

YAML and TOML sources are available in the flaggax repository.

Custom Sources and Extractors

You can implement your own Sources and Extractors in case your configuration is in a different format. Check out the Source and Extractor interfaces in the package documentation.

Reference

License

MIT, see LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].