From 76cee1f621e3463d73b7a892207b945503cad403 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sat, 18 Feb 2017 11:52:37 -0800 Subject: [PATCH] fix: environment variables should take precedence over config file (#81) BREAKING CHANGE: environment variables will now override config files (args, env, config-file, config-object) --- index.js | 8 ++++---- test/yargs-parser.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1a04d559..b71faf58 100644 --- a/index.js +++ b/index.js @@ -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) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index c9c59993..5b59c615 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -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', @@ -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 () {