Skip to content

Commit 0997288

Browse files
committed
fix: context should override parsed argv (#786)
BREAKING CHANGE: context now takes precedence over argv and defaults
1 parent a8528e6 commit 0997288

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

test/yargs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ describe('yargs dsl tests', function () {
768768
a1.foo.should.equal('bar')
769769
a1.context.should.equal('look at me go!')
770770
})
771+
772+
// see https://github.com/yargs/yargs/issues/724
773+
it('overrides parsed value of argv with context object', function () {
774+
var a1 = yargs.parse('-x=33', {
775+
x: 42
776+
})
777+
a1.x.should.equal(42)
778+
})
771779
})
772780

773781
// yargs.parse(['foo', '--bar'], function (err, argv, output) {}

yargs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ function Yargs (processArgs, cwd, parentRequire) {
935935
options.configuration = pkgUp()['yargs'] || {}
936936
const parsed = Parser.detailed(args, options)
937937
var argv = parsed.argv
938-
if (parseContext) argv = assign(parseContext, argv)
938+
if (parseContext) argv = assign(argv, parseContext)
939939
var aliases = parsed.aliases
940940

941941
argv.$0 = self.$0

0 commit comments

Comments
 (0)