{"action":"created","issue":{"url":"https://api.github.com/repos/yargs/yargs/issues/308","repository_url":"https://api.github.com/repos/yargs/yargs","labels_url":"https://api.github.com/repos/yargs/yargs/issues/308/labels{/name}","comments_url":"https://api.github.com/repos/yargs/yargs/issues/308/comments","events_url":"https://api.github.com/repos/yargs/yargs/issues/308/events","html_url":"https://github.com/yargs/yargs/pull/308","id":119884394,"number":308,"title":"Apply env vars to argv via prefix-based API","user":{"login":"nexdrew","id":1929625,"avatar_url":"https://avatars.githubusercontent.com/u/1929625?v=3","gravatar_id":"","url":"https://api.github.com/users/nexdrew","html_url":"https://github.com/nexdrew","followers_url":"https://api.github.com/users/nexdrew/followers","following_url":"https://api.github.com/users/nexdrew/following{/other_user}","gists_url":"https://api.github.com/users/nexdrew/gists{/gist_id}","starred_url":"https://api.github.com/users/nexdrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nexdrew/subscriptions","organizations_url":"https://api.github.com/users/nexdrew/orgs","repos_url":"https://api.github.com/users/nexdrew/repos","events_url":"https://api.github.com/users/nexdrew/events{/privacy}","received_events_url":"https://api.github.com/users/nexdrew/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2015-12-02T07:31:57Z","updated_at":"2016-09-15T16:04:34Z","closed_at":"2015-12-03T16:31:54Z","pull_request":{"url":"https://api.github.com/repos/yargs/yargs/pulls/308","html_url":"https://github.com/yargs/yargs/pull/308","diff_url":"https://github.com/yargs/yargs/pull/308.diff","patch_url":"https://github.com/yargs/yargs/pull/308.patch"},"body":"First stab at env var support, implementing [@bcoe's suggestions](https://github.com/bcoe/yargs/issues/305#issuecomment-160851479) as discussed in #305.\r\n\r\nThis will allow env vars matching a given prefix to be parsed and applied to `argv` via simple configuration method `.env('PREFIX')`. Prefix can be omitted to apply _all_ env vars to `argv`.\r\n\r\nAliases and type configuration are supported when args are defined by env vars.\r\n\r\nNew order of precedence for program argument values:\r\n\r\n1. CLI flags\r\n2. Config file (if configured)\r\n3. Env var (if configured)\r\n4. Default values (if configured)\r\n\r\nThere is also a special case to support specification of a config file via env var.\r\n\r\nFor more details, consult the additional README content or the unit tests.\r\n\r\nThings not addressed by this PR:\r\n\r\n- Indication of env var support in usage/help text\r\n- Ability to explicitly map a configured option to an arbitrary env var name\r\n- Support for displaying env var value over configured default value in usage/help text"},"comment":{"url":"https://api.github.com/repos/yargs/yargs/issues/comments/247372440","html_url":"https://github.com/yargs/yargs/pull/308#issuecomment-247372440","issue_url":"https://api.github.com/repos/yargs/yargs/issues/308","id":247372440,"user":{"login":"bcoe","id":194609,"avatar_url":"https://avatars.githubusercontent.com/u/194609?v=3","gravatar_id":"","url":"https://api.github.com/users/bcoe","html_url":"https://github.com/bcoe","followers_url":"https://api.github.com/users/bcoe/followers","following_url":"https://api.github.com/users/bcoe/following{/other_user}","gists_url":"https://api.github.com/users/bcoe/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoe/subscriptions","organizations_url":"https://api.github.com/users/bcoe/orgs","repos_url":"https://api.github.com/users/bcoe/repos","events_url":"https://api.github.com/users/bcoe/events{/privacy}","received_events_url":"https://api.github.com/users/bcoe/received_events","type":"User","site_admin":false},"created_at":"2016-09-15T16:04:34Z","updated_at":"2016-09-15T16:04:34Z","body":"@nexdrew @jaridmargolin another argument for config file taking precedence over environment, is this:\r\n\r\n```yaml\r\nFOO=${MY_ENVIRONMENT_VARIABLE}\r\nBAR=banana\r\n```\r\n\r\nIf we eventually allow for config files, like the `.npmrc` format, these files could defer to an environment variable; the reverse is harder."}}
{"actor":{"display_login":"bcoe"}}