envvar icon indicating copy to clipboard operation
envvar copied to clipboard

Display all required environment variables

Open albrow opened this issue 10 years ago • 2 comments

See https://github.com/plaid/style/pull/37 for a background.

I believe there are two things we should do to make environment variables more pleasant to work with.

  1. We should add a --help flag to all service executables which prints out the required environment variables, and optionally some other information about the service.
  2. When you forget a required env var, all required env vars should be printed out, not just the one you forgot. This will reduce time to get up and running and eliminate the cycle of add the env var, run the service, add another env var, run it again, etc. It might make sense to just print the help text in this case.

albrow avatar Sep 29 '15 19:09 albrow

We could provide a new function which takes and returns a mapping, or report all failures.

var GITHUB_API_TOKEN = envvar.string('GITHUB_API_TOKEN');
var HTTP_MAX_SOCKETS = envvar.number('HTTP_MAX_SOCKETS');
var ENABLE_FEATURE_X = envvar.boolean('ENABLE_FEATURE_X', false);

The above could then be written:

//  env :: { GITHUB_API_TOKEN :: String
//         , HTTP_MAX_SOCKETS :: Number
//         , ENABLE_FEATURE_X :: Boolean
//         }
var env = envvar.extract({
  GITHUB_API_TOKEN: {type: 'string'},
  HTTP_MAX_SOCKETS: {type: 'number'},
  ENABLE_FEATURE_X: {type: 'boolean', default: false},
});

The mapping provided to envvar.extract could be defined in a JSON file, and could contain additional properties. This JSON file could then be used to generate --help text. Actually generating this text is likely out of scope for this project, as the formatting would depend on the tool being used to generate the rest of the string.

davidchambers avatar Sep 29 '15 19:09 davidchambers