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

fix: default '--' to undefined, allowing for smoother transition in yargs #90

Merged
merged 1 commit into from
May 1, 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: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ function parse (args, opts) {

var argv = { _: [] }

if (notFlagsOption) {
argv[notFlagsArgv] = []
}

Object.keys(flags.bools).forEach(function (key) {
setArg(key, !(key in defaults) ? false : defaults[key])
setDefaulted(key)
Expand Down Expand Up @@ -296,6 +292,8 @@ function parse (args, opts) {
if (!hasKey(argv, key.split('.'))) setArg(key, 0)
})

// '--' defaults to undefined.
if (notFlagsOption && notFlags.length) argv[notFlagsArgv] = []
notFlags.forEach(function (key) {
argv[notFlagsArgv].push(key)
})
Expand Down
12 changes: 12 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ var path = require('path')
describe('yargs-parser', function () {
it('should parse a "short boolean"', function () {
var parse = parser([ '-b' ])
parse.should.not.have.property('--')
parse.should.have.property('b').to.be.ok.and.be.a('boolean')
parse.should.have.property('_').with.length(0)
})

it('should parse a "long boolean"', function () {
var parse = parser('--bool')
parse.should.not.have.property('--')
parse.should.have.property('bool', true)
parse.should.have.property('_').with.length(0)
})
Expand Down Expand Up @@ -113,6 +115,16 @@ 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