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
8 changes: 8 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ async function e_call(argv, script, ...args) {
return;
}

if (argv.verbose !== undefined &&
// this must exclude NaN -- yargs default value for numeric type
!(argv.verbose >= 0 && argv.verbose <= 5)) {
console.warn("invalid value for --verbose option: must be a number between 0 and 5");
process.exit(1);
return;
}

return new Promise(resolve => {
let _path = el_script(script);

Expand Down
12 changes: 12 additions & 0 deletions test/jest/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ describe("options", () => {
});
});

describe("verbose option", () => {
it("should error if no number is given", async () => {
await expect(ctx.runEask("info -v")).rejects.toMatchObject({ code: 1 });
});

it("should error if the number is omitted before the next option", async () => {
await expect(ctx.runEask("info -v --no-color")).rejects.toMatchObject({
code: 1,
});
});
});

test.each([
"-a",
"--all",
Expand Down
Loading