Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call default subcommand with unknown options #1047

Merged
merged 1 commit into from Sep 21, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
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
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
@@ -1,2 +1,5 @@
#!/usr/bin/env node
console.log('default');
if (process.argv.length > 2) {
console.log(process.argv.slice(2));
}