Skip to content

Commit

Permalink
fix: environment variables should take precedence over config file (#81)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: environment variables will now override config files (args, env, config-file, config-object)
  • Loading branch information
bcoe authored Feb 18, 2017
1 parent 924b014 commit 76cee1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 76cee1f

Please sign in to comment.