Skip to content

Commit

Permalink
fix: --help with default command should print top-level help (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Mar 3, 2017
1 parent 5334370 commit 9c03fa4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions test/usage.js
Expand Up @@ -2521,4 +2521,28 @@ describe('usage tests', function () {
])
})
})

describe('default command', function () {
it('--help should display top-level help with no command given', function () {
var r = checkUsage(function () {
return yargs('--help')
.command(['list [pattern]', 'ls', '*'], 'List key-value pairs for pattern', {}, function () {})
.command('get <key>', 'Get value for key', {}, function () {})
.command('set <key> [value]', 'Set value for key', {}, function () {})
.help()
.argv
})

r.logs[0].split('\n').should.deep.equal([
'Commands:',
' list [pattern] List key-value pairs for pattern [default] [aliases: ls]',
' get <key> Get value for key',
' set <key> [value] Set value for key',
'',
'Options:',
' --help Show help [boolean]',
''
])
})
})
})
2 changes: 1 addition & 1 deletion yargs.js
Expand Up @@ -1011,7 +1011,7 @@ function Yargs (processArgs, cwd, parentRequire) {
self.showCompletionScript()
self.exit(0)
}
} else if (command.hasDefaultCommand()) {
} else if (command.hasDefaultCommand() && !argv[helpOpt]) {
setPlaceholderKeys(argv)
return command.runCommand(null, self, parsed)
}
Expand Down

0 comments on commit 9c03fa4

Please sign in to comment.