Skip to content

Commit

Permalink
fix: changed parsing of the command string to ignore extra spaces (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbyerly authored and bcoe committed Aug 20, 2016
1 parent e13312d commit e8e5a72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/command.js
Expand Up @@ -85,7 +85,8 @@ module.exports = function (yargs, usage, validation) {
}

function parseCommand (cmd) {
var splitCommand = cmd.split(/\s/)
var extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ')
var splitCommand = extraSpacesStrippedCommand.split(/\s/)
var bregex = /\.*[\][<>]/g
var parsedCommand = {
cmd: (splitCommand.shift()).replace(bregex, ''),
Expand Down
15 changes: 15 additions & 0 deletions test/command.js
Expand Up @@ -621,4 +621,19 @@ describe('Command', function () {
.argv
argv.should.have.property('someone').and.equal('Leslie')
})

// addresses https://github.com/yargs/yargs/issues/540
it('ignores extra spaces in command string', function () {
var y = yargs([])
.command('foo [awesome]', 'my awesome command', function (yargs) {
return yargs
})
var command = y.getCommandInstance()
var handlers = command.getCommandHandlers()
handlers.foo.demanded.should.not.include({
cmd: '',
variadic: false
})
handlers.foo.demanded.should.have.lengthOf(0)
})
})

0 comments on commit e8e5a72

Please sign in to comment.