Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --help with default command should print top-level help #810

Merged
merged 1 commit into from Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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