Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert populate-- logic #91

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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