diff --git a/README.md b/README.md index a3305d4e..d1817fcc 100644 --- a/README.md +++ b/README.md @@ -250,13 +250,15 @@ node example.js -x 1 2 -x 3 4 { _: [], x: [[1, 2], [3, 4]] } ``` -### `populate--` +### populate -- -* default: `true`. +* default: `false`. +* key: `populate--` Should unparsed flags be stored in `--` or `_`. _If disabled:_ + ```sh node example.js a -b -- x y { _: [ 'a', 'x', 'y' ], b: true } diff --git a/index.js b/index.js index 15936de8..73154066 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ function parse (args, opts) { 'boolean-negation': true, 'duplicate-arguments-array': true, 'flatten-duplicate-arrays': true, - 'populate--': true + 'populate--': false }, opts.configuration) var defaults = opts.default || {} var configObjects = opts.configObjects || [] diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 23c8e642..373f8d3c 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -115,16 +115,6 @@ describe('yargs-parser', function () { parse.should.have.property('_').and.deep.equal(['bare', '--not-a-flag', '-', '-h', '-multi', '--', 'eek']) }) - it('should not populate "--" if parsing was not stopped', function () { - var parse = parser([ '-b' ]) - parse.should.not.have.property('--') - }) - - it('should populate "--" if parsing is stopped', function () { - var parse = parser([ '-b', '--', 'foo bar' ]) - parse.should.have.property('--') - }) - it('should parse numbers appropriately', function () { var argv = parser([ '-x', '1234', @@ -2222,25 +2212,27 @@ describe('yargs-parser', function () { }) describe('populate--', function () { - it('should populate "_" if "populate-- false', function () { + it('should populate "_" by default', function () { var result = parser([ 'bare', '--', '-h', 'eek', '--' - ], { - configuration: {'populate--': false} - }) + ]) result.should.have.property('_').and.deep.equal(['bare', '-h', 'eek', '--']) result.should.not.have.property('--') }) - it('should populate the "--" array by default', function () { + it('should populate the "--" if populate-- is "true"', function () { var result = parser([ '--name=meowmers', 'bare', '-cats', 'woo', 'moxy', '-h', 'awesome', '--multi=quux', '--key', 'value', '-b', '--bool', '--no-meep', '--multi=baz', '--', '--not-a-flag', '-', '-h', '-multi', '--', 'eek' - ]) + ], { + configuration: { + 'populate--': true + } + }) result.should.have.property('c', true) result.should.have.property('a', true) result.should.have.property('t', true)