Skip to content

Commit

Permalink
fix: we now respect the order of _ when applying commands (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jul 7, 2016
1 parent e6cf29e commit ed86b78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions test/command.js
Expand Up @@ -455,4 +455,20 @@ describe('Command', function () {
])
})
})

// addresses https://github.com/yargs/yargs/issues/514.
it('respects order of positional arguments when matching commands', function () {
var output = []
yargs('bar foo')
.command('foo', 'foo command', function (yargs) {
output.push('foo')
})
.command('bar', 'bar command', function (yargs) {
output.push('bar')
})
.argv

output.should.include('bar')
output.should.not.include('foo')
})
})
4 changes: 2 additions & 2 deletions yargs.js
Expand Up @@ -647,8 +647,8 @@ function Yargs (processArgs, cwd, parentRequire) {
// if there's a handler associated with a
// command defer processing to it.
var handlerKeys = command.getCommands()
for (var i = 0, cmd; (cmd = handlerKeys[i]) !== undefined; i++) {
if (~argv._.indexOf(cmd) && cmd !== completionCommand) {
for (var i = 0, cmd; (cmd = argv._[i]) !== undefined; i++) {
if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
setPlaceholderKeys(argv)
return command.runCommand(cmd, self, parsed)
}
Expand Down

0 comments on commit ed86b78

Please sign in to comment.