kelseyhightower / envconfig

Golang library for managing configuration data from environment variables
MIT License
5.01k stars 377 forks source link

Feature Request: Ability to get list of ENV variables #176

Closed MistaTwista closed 4 years ago

MistaTwista commented 4 years ago

Feature Request

It may be helpful if envconfig can provide list of env variables for config struct. It can be just []string with list of vars or even more smarty, []EnvVar, like:

type EnvVar struct {
  Name string
  Required bool
  Ignored bool
  SplitWords bool
  Default string
  etc...
}

so user can do whatever he needs with this list

Motivation

When new developer started to work with project or DevOps team wants to get list of configurable ENV or we just wanted to have actual documentation about ENV configurable variables.

Example

Something like

type Specification struct {
    ManualOverride1 string `envconfig:"manual_override_1"`
    DefaultVar string `default:"foobar"`
    RequiredVar string `required:"true"`
    IgnoredVar string `ignored:"true"`
    AutoSplitVar string `split_words:"true"`
    RequiredAndAutoSplitVar string `required:"true" split_words:"true"`
}

var s Specification
list := envconfig.ExtractList("myapp", &s)

So the list will have full list of ENV vars that can configure our App

What do you think? If it's useful I can make PR for this feature

colega commented 4 years ago

Looks like you're looking for the Usage function: it can render a plain list with a custom format, or even richer formats

MistaTwista commented 4 years ago

This is exactly what I need. I missed it somehow, sorry :(