From 8674b97bd40e27760196203ff8f0eed3450f63b6 Mon Sep 17 00:00:00 2001 From: nexdrew Date: Thu, 2 Mar 2017 10:05:36 -0500 Subject: [PATCH] fix: --help with default command should print top-level help --- test/usage.js | 24 ++++++++++++++++++++++++ yargs.js | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/test/usage.js b/test/usage.js index 87635aa21..cac6dd63b 100644 --- a/test/usage.js +++ b/test/usage.js @@ -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 ', 'Get value for key', {}, function () {}) + .command('set [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 Get value for key', + ' set [value] Set value for key', + '', + 'Options:', + ' --help Show help [boolean]', + '' + ]) + }) + }) }) diff --git a/yargs.js b/yargs.js index 2b911d9a2..a34091151 100644 --- a/yargs.js +++ b/yargs.js @@ -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) }