Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
13 changes: 10 additions & 3 deletions tests/command.executableSubcommand.default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
3 changes: 3 additions & 0 deletions tests/fixtures/pm-default
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/usr/bin/env node
console.log('default');
if (process.argv.length > 2) {
console.log(process.argv.slice(2));
}