Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: environment variables should take precedence over config file #81

Merged
merged 1 commit into from Feb 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -273,14 +273,14 @@ function parse (args, opts) {

// order of precedence:
// 1. command line arg
// 2. value from config file
// 3. value from config objects
// 4. value from env var
// 2. value from env var
// 3. value from config file
// 4. value from config objects
// 5. configured default value
applyEnvVars(argv, true) // special case: check env vars that point to config file
applyEnvVars(argv, false)
setConfig(argv)
setConfigObjects()
applyEnvVars(argv, false)
applyDefaultsAndAliases(argv, flags.aliases, defaults)
applyCoercions(argv)

Expand Down
4 changes: 2 additions & 2 deletions test/yargs-parser.js
Expand Up @@ -1697,7 +1697,7 @@ describe('yargs-parser', function () {
})

var jsonPath = path.resolve(__dirname, './fixtures/config.json')
it('should prefer config file value over env var', function () {
it('should prefer environment variables over config file', function () {
process.env.CFG_HERP = 'zerp'
var result = parser(['--cfg', jsonPath], {
envPrefix: 'CFG',
Expand All @@ -1708,7 +1708,7 @@ describe('yargs-parser', function () {
}
})

result.herp.should.equal('derp')
result.herp.should.equal('zerp')
})

it('should support an env var value as config file option', function () {
Expand Down