Skip to content

Commit

Permalink
chore: revert populate-- logic (#91)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: populate-- now defaults to false.
  • Loading branch information
bcoe committed May 2, 2017
1 parent 0552218 commit 6003e6d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []
Expand Down
24 changes: 8 additions & 16 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6003e6d

Please sign in to comment.