Skip to content

Commit

Permalink
fix: help now takes precedence over command recommendation (yargs#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 1, 2017
1 parent 89456d9 commit 17e3567
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions test/yargs.js
Expand Up @@ -338,15 +338,14 @@ describe('yargs dsl tests', function () {
})

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

parser.parse('boat help', {}, function (err, _argv, output) {
// it should not have printed the help text twice!
err.message.should.equal('Did you mean goat?')
if (err) return done(err)
output.split('Commands:').length.should.equal(2)
return done()
})
Expand Down
2 changes: 1 addition & 1 deletion yargs.js
Expand Up @@ -1002,7 +1002,7 @@ function Yargs (processArgs, cwd, parentRequire) {

// recommend a command if recommendCommands() has
// been enabled, and no commands were found to execute
if (recommendCommands && firstUnknownCommand) {
if (recommendCommands && firstUnknownCommand && !argv[helpOpt]) {
validation.recommendCommands(firstUnknownCommand, handlerKeys)
}
}
Expand Down

0 comments on commit 17e3567

Please sign in to comment.