Skip to content

Commit

Permalink
fix: running parse() multiple times on the same yargs instance caused…
Browse files Browse the repository at this point in the history
… exception if help() enabled (#790)
  • Loading branch information
bcoe committed Feb 26, 2017
1 parent deba89b commit 21b1e35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/command.js
Expand Up @@ -747,6 +747,21 @@ describe('Command', function () {
counter.should.equal(2)
})

// addresses: https://github.com/yargs/yargs/issues/776
it('allows command handler to be invoked repeatedly when help is enabled', function (done) {
var counter = 0
var y = yargs([])
.command('foo', 'the foo command', {}, function (argv) {
counter++
})
.help()
y.parse(['foo'], function () {})
y.parse(['foo'], function () {
counter.should.equal(2)
return done()
})
})

// addresses https://github.com/yargs/yargs/issues/522
it('does not require builder function to return', function () {
var argv = yargs('yo')
Expand Down
2 changes: 1 addition & 1 deletion yargs.js
Expand Up @@ -967,7 +967,7 @@ function Yargs (processArgs, cwd, parentRequire) {
// consider any multi-char helpOpt alias as a valid help command
// unless all helpOpt aliases are single-char
// note that parsed.aliases is a normalized bidirectional map :)
var helpCmds = [helpOpt].concat(aliases[helpOpt])
var helpCmds = [helpOpt].concat(aliases[helpOpt] || [])
var multiCharHelpCmds = helpCmds.filter(function (k) {
return k.length > 1
})
Expand Down

0 comments on commit 21b1e35

Please sign in to comment.