Skip to content

Commit

Permalink
chore: upgrade yargs-parser (#867)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: environment variables will now override config files, '--' is now populated rather than '_' when parsing is stopped.
  • Loading branch information
bcoe committed May 1, 2017
1 parent 17e3567 commit 8f9c6c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -1938,7 +1938,7 @@ parsing tricks
stop parsing
------------

Use `--` to stop parsing flags and stuff the remainder into `argv._`.
Use `--` to stop parsing flags and stuff the remainder into `argv['--']`.

$ node examples/reflect.js -a 1 -b 2 -- -c 3 -d 4
{ _: [ '-c', '3', '-d', '4' ],
Expand Down
5 changes: 3 additions & 2 deletions lib/validation.js
@@ -1,4 +1,5 @@
const objFilter = require('./obj-filter')
const specialKeys = ['$0', '--', '_']

// validation-type-stuff, missing params,
// bad implications, custom checks.
Expand Down Expand Up @@ -131,7 +132,7 @@ module.exports = function (yargs, usage, y18n) {
})

Object.keys(argv).forEach(function (key) {
if (key !== '$0' && key !== '_' &&
if (specialKeys.indexOf(key) === -1 &&
!descriptions.hasOwnProperty(key) &&
!demandedOptions.hasOwnProperty(key) &&
!positionalMap.hasOwnProperty(key) &&
Expand Down Expand Up @@ -167,7 +168,7 @@ module.exports = function (yargs, usage, y18n) {
if (!Object.keys(options.choices).length) return

Object.keys(argv).forEach(function (key) {
if (key !== '$0' && key !== '_' &&
if (specialKeys.indexOf(key) === -1 &&
options.choices.hasOwnProperty(key)) {
[].concat(argv[key]).forEach(function (value) {
// TODO case-insensitive configurability
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"string-width": "^1.0.2",
"which-module": "^1.0.0",
"y18n": "^3.2.1",
"yargs-parser": "^5.0.0"
"yargs-parser": "^6.0.1"
},
"devDependencies": {
"chai": "^3.4.1",
Expand Down
10 changes: 10 additions & 0 deletions test/yargs.js
Expand Up @@ -1985,6 +1985,16 @@ describe('yargs dsl tests', function () {
expect(err).to.exist
})
})

describe('stop parsing', () => {
it('populates "--" with unparsed arguments after "--"', () => {
const argv = yargs.parse('--foo 33 --bar=99 -- --grep=foobar')
argv.foo.should.equal(33)
argv.bar.should.equal(99)
argv['--'].length.should.equal(1)
argv['--'][0].should.equal('--grep=foobar')
})
})
})

describe('yargs context', function () {
Expand Down

0 comments on commit 8f9c6c6

Please sign in to comment.