Skip to content

Commit

Permalink
fix(@whook/cli): ensure CLI commands fail with args errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Mar 23, 2021
1 parent a70a77d commit 240b314
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/whook-cli/src/services/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ async function initCommand({ commandHandler, log }) {
'error',
`Argument "${err.params[0][0].params.missingProperty}" is required.`,
);
return;
throw err;
}
}
if (err.params[0][0].keyword === 'additionalProperties') {
if (err.params[0][0].params.additionalProperty === '_') {
log('error', 'No anonymous arguments allowed.');
return;
throw err;
}
if (err.params[0][0].params.additionalProperty) {
log(
'error',
`Argument "${err.params[0][0].params.additionalProperty}" not allowed.`,
);
return;
throw err;
}
}
log(
Expand All @@ -37,7 +37,7 @@ async function initCommand({ commandHandler, log }) {
err.params[0][0].message,
err.params[0][0].params,
);
return;
throw err;
}
throw err;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/whook-example/src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { exec } from 'child_process';
import YError from 'yerror';

describe('commands should work', () => {
it('with ls', async () => {
Expand Down Expand Up @@ -36,12 +37,12 @@ describe('commands should work', () => {
});

async function execCommand(
command,
command: string,
): Promise<{ stdout: string; stderr: string }> {
return new Promise((resolve, reject) => {
exec(command, (err, stdout, stderr) => {
if (err) {
reject(err);
reject(YError.wrap(err, 'E_COMMAND_FAILURE', stdout, stderr));
return;
}
resolve({ stdout, stderr });
Expand Down

0 comments on commit 240b314

Please sign in to comment.