diff --git a/src/util.js b/src/util.js index 86a5dc12..febe4125 100644 --- a/src/util.js +++ b/src/util.js @@ -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); diff --git a/test/jest/options.test.js b/test/jest/options.test.js index bcc97e0b..42aa4323 100644 --- a/test/jest/options.test.js +++ b/test/jest/options.test.js @@ -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",