Skip to content

Commit 17e3567

Browse files
authored
fix: help now takes precedence over command recommendation (#866)
1 parent 89456d9 commit 17e3567

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

test/yargs.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,14 @@ describe('yargs dsl tests', function () {
338338
})
339339

340340
// see: https://github.com/yargs/yargs/issues/822
341-
it('does not print help message if recommendation has been made', function (done) {
341+
it('does not print command recommendation if help message will be shown', function (done) {
342342
const parser = yargs()
343343
.command('goat')
344344
.help()
345345
.recommendCommands()
346346

347347
parser.parse('boat help', {}, function (err, _argv, output) {
348-
// it should not have printed the help text twice!
349-
err.message.should.equal('Did you mean goat?')
348+
if (err) return done(err)
350349
output.split('Commands:').length.should.equal(2)
351350
return done()
352351
})

yargs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ function Yargs (processArgs, cwd, parentRequire) {
10021002

10031003
// recommend a command if recommendCommands() has
10041004
// been enabled, and no commands were found to execute
1005-
if (recommendCommands && firstUnknownCommand) {
1005+
if (recommendCommands && firstUnknownCommand && !argv[helpOpt]) {
10061006
validation.recommendCommands(firstUnknownCommand, handlerKeys)
10071007
}
10081008
}

0 commit comments

Comments
 (0)