Skip to content

Commit be65728

Browse files
nexdrewbcoe
authored andcommitted
feat: apply .env() globally (#553)
1 parent 317c62c commit be65728

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

test/command.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,23 @@ describe('Command', function () {
547547
})
548548
})
549549

550+
// see: https://github.com/yargs/yargs/pull/553
551+
it('preserves top-level envPrefix', function () {
552+
process.env.FUN_DIP_STICK = 'yummy'
553+
process.env.FUN_DIP_POWDER = 'true'
554+
yargs('eat')
555+
.env('FUN_DIP')
556+
.global('stick') // this does not actually need to be global
557+
.command('eat', 'Adult supervision recommended', function (yargs) {
558+
return yargs.boolean('powder').exitProcess(false)
559+
}, function (argv) {
560+
argv.should.have.property('powder').and.be.true
561+
argv.should.have.property('stick').and.equal('yummy')
562+
})
563+
.exitProcess(false)
564+
.argv
565+
})
566+
550567
// addresses https://github.com/yargs/yargs/issues/514.
551568
it('respects order of positional arguments when matching commands', function () {
552569
var output = []

test/yargs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe('yargs dsl tests', function () {
226226
normalize: [],
227227
number: [],
228228
config: {},
229-
envPrefix: undefined,
229+
envPrefix: 'YARGS', // preserved as global
230230
global: ['help'],
231231
demanded: {}
232232
}

yargs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function Yargs (processArgs, cwd, parentRequire) {
113113
})
114114
})
115115

116-
tmpOptions.envPrefix = undefined
116+
tmpOptions.envPrefix = options.envPrefix
117117
options = tmpOptions
118118

119119
// if this is the first time being executed, create

0 commit comments

Comments
 (0)