diff --git a/index.js b/index.js index ad5d82f4a..b22b1d07b 100644 --- a/index.js +++ b/index.js @@ -761,7 +761,7 @@ Command.prototype.parseArgs = function(args, unknown) { // If there were no args and we have unknown options, // then they are extraneous and we need to error. - if (unknown.length > 0) { + if (unknown.length > 0 && !this.defaultExecutable) { this.unknownOption(unknown[0]); } if (this.commands.length === 0 && diff --git a/tests/command.executableSubcommand.default.test.js b/tests/command.executableSubcommand.default.test.js index 867a660df..3bbae5c0d 100644 --- a/tests/command.executableSubcommand.default.test.js +++ b/tests/command.executableSubcommand.default.test.js @@ -10,9 +10,16 @@ test('when default subcommand and no command then call default', (done) => { }); }); -test('when default subcommand and unrecognised argument then call default', (done) => { - childProcess.execFile(bin, ['unrecognised-argument'], { }, function(_error, stdout, stderr) { - expect(stdout).toBe('default\n'); +test('when default subcommand and unrecognised argument then call default with argument', (done) => { + childProcess.execFile(bin, ['an-argument'], { }, function(_error, stdout, stderr) { + expect(stdout).toBe("default\n[ 'an-argument' ]\n"); + done(); + }); +}); + +test('when default subcommand and unrecognised option then call default with option', (done) => { + childProcess.execFile(bin, ['--an-option'], { }, function(_error, stdout, stderr) { + expect(stdout).toBe("default\n[ '--an-option' ]\n"); done(); }); }); diff --git a/tests/fixtures/pm-default b/tests/fixtures/pm-default index c053cca81..09888b08a 100755 --- a/tests/fixtures/pm-default +++ b/tests/fixtures/pm-default @@ -1,2 +1,5 @@ #!/usr/bin/env node console.log('default'); +if (process.argv.length > 2) { + console.log(process.argv.slice(2)); +}