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/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() 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)