Skip to content

Commit

Permalink
feat: add support for numeric commands (yargs#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
sputnik13 authored and bcoe committed Mar 28, 2017
1 parent c748dd2 commit fde0564
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/command.js
Expand Up @@ -1317,4 +1317,14 @@ describe('Command', function () {
called.should.equal(false)
r.errors.should.match(/Missing required argument/)
})

it('should support numeric commands', function () {
var output = []
yargs('1')
.command('1', 'numeric command', function (yargs) {
output.push('1')
})
.argv
output.should.include('1')
})
})
3 changes: 2 additions & 1 deletion yargs.js
Expand Up @@ -983,7 +983,8 @@ function Yargs (processArgs, cwd, parentRequire) {
var handlerKeys = command.getCommands()
if (handlerKeys.length) {
var firstUnknownCommand
for (var i = 0, cmd; (cmd = argv._[i]) !== undefined; i++) {
for (var i = 0, cmd; argv._[i] !== undefined; i++) {
cmd = String(argv._[i])
if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
setPlaceholderKeys(argv)
return command.runCommand(cmd, self, parsed)
Expand Down

0 comments on commit fde0564

Please sign in to comment.