From 5a7362235579079e75b2f35ccf8b880e06dbde7d Mon Sep 17 00:00:00 2001 From: Steve Zhu Date: Sun, 26 Feb 2017 03:00:28 -0600 Subject: [PATCH 1/2] fix: positional arguments of sub-command --- .editorconfig | 7 ------- lib/command.js | 3 ++- yargs.js | 4 ++++ 3 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 91c336188..000000000 --- a/.editorconfig +++ /dev/null @@ -1,7 +0,0 @@ -root = true - -[*.js] -end_of_line = lf -indent_style = space -indent_size = 2 -insert_final_newline = true diff --git a/lib/command.js b/lib/command.js index 27fe6d02c..c49555ac3 100644 --- a/lib/command.js +++ b/lib/command.js @@ -224,9 +224,10 @@ module.exports = function (yargs, usage, validation) { // we apply validation post-hoc, so that custom // checks get passed populated positional arguments. - yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error) + if (!yargs._hasOutput()) yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error) if (commandHandler.handler && !yargs._hasOutput()) { + yargs._setHasOutput() commandHandler.handler(innerArgv) } diff --git a/yargs.js b/yargs.js index 1843443f7..2b911d9a2 100644 --- a/yargs.js +++ b/yargs.js @@ -897,6 +897,10 @@ function Yargs (processArgs, cwd, parentRequire) { return hasOutput } + self._setHasOutput = function () { + hasOutput = true + } + var recommendCommands self.recommendCommands = function (recommend) { argsert('[boolean]', [recommend], arguments.length) From 1ffb44cbf2b94269a503dda06bd72657afd821d7 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Sun, 26 Feb 2017 01:56:04 -0800 Subject: [PATCH 2/2] fix: add test broken strict check --- test/command.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/command.js b/test/command.js index dfa5c7060..a792653a7 100644 --- a/test/command.js +++ b/test/command.js @@ -1024,6 +1024,19 @@ describe('Command', function () { }) }) + // address https://github.com/yargs/yargs/issues/795 + it('does not fail strict check due to postional command arguments in nested commands', function (done) { + yargs() + .strict() + .command('hi', 'The hi command', function (yargs) { + yargs.command('ben ', 'ben command', function () {}, function () {}) + }) + .parse('hi ben 99', function (err, argv, output) { + expect(err).to.equal(null) + return done() + }) + }) + it('does not fire command if validation fails', function (done) { var commandRun = false yargs()