Skip to content

Commit 07e39b7

Browse files
committed
fix: running parse() multiple times on the same yargs instance caused exception if help() enabled (#790)
1 parent 48575cd commit 07e39b7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

test/command.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,21 @@ describe('Command', function () {
747747
counter.should.equal(2)
748748
})
749749

750+
// addresses: https://github.com/yargs/yargs/issues/776
751+
it('allows command handler to be invoked repeatedly when help is enabled', function (done) {
752+
var counter = 0
753+
var y = yargs([])
754+
.command('foo', 'the foo command', {}, function (argv) {
755+
counter++
756+
})
757+
.help()
758+
y.parse(['foo'], function () {})
759+
y.parse(['foo'], function () {
760+
counter.should.equal(2)
761+
return done()
762+
})
763+
})
764+
750765
// addresses https://github.com/yargs/yargs/issues/522
751766
it('does not require builder function to return', function () {
752767
var argv = yargs('yo')

yargs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ function Yargs (processArgs, cwd, parentRequire) {
967967
// consider any multi-char helpOpt alias as a valid help command
968968
// unless all helpOpt aliases are single-char
969969
// note that parsed.aliases is a normalized bidirectional map :)
970-
var helpCmds = [helpOpt].concat(aliases[helpOpt])
970+
var helpCmds = [helpOpt].concat(aliases[helpOpt] || [])
971971
var multiCharHelpCmds = helpCmds.filter(function (k) {
972972
return k.length > 1
973973
})

0 commit comments

Comments
 (0)