Skip to content

Commit

Permalink
feat: apply .env() globally (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew authored and bcoe committed Aug 7, 2016
1 parent 317c62c commit be65728
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions test/command.js
Expand Up @@ -547,6 +547,23 @@ describe('Command', function () {
})
})

// see: https://github.com/yargs/yargs/pull/553
it('preserves top-level envPrefix', function () {
process.env.FUN_DIP_STICK = 'yummy'
process.env.FUN_DIP_POWDER = 'true'
yargs('eat')
.env('FUN_DIP')
.global('stick') // this does not actually need to be global
.command('eat', 'Adult supervision recommended', function (yargs) {
return yargs.boolean('powder').exitProcess(false)
}, function (argv) {
argv.should.have.property('powder').and.be.true
argv.should.have.property('stick').and.equal('yummy')
})
.exitProcess(false)
.argv
})

// addresses https://github.com/yargs/yargs/issues/514.
it('respects order of positional arguments when matching commands', function () {
var output = []
Expand Down
2 changes: 1 addition & 1 deletion test/yargs.js
Expand Up @@ -226,7 +226,7 @@ describe('yargs dsl tests', function () {
normalize: [],
number: [],
config: {},
envPrefix: undefined,
envPrefix: 'YARGS', // preserved as global
global: ['help'],
demanded: {}
}
Expand Down
2 changes: 1 addition & 1 deletion yargs.js
Expand Up @@ -113,7 +113,7 @@ function Yargs (processArgs, cwd, parentRequire) {
})
})

tmpOptions.envPrefix = undefined
tmpOptions.envPrefix = options.envPrefix
options = tmpOptions

// if this is the first time being executed, create
Expand Down

0 comments on commit be65728

Please sign in to comment.