Skip to content

Commit f7d8a90

Browse files
authored
verbose option should check for NaN (#365)
* Fix: vebose option should error if no number is given * Add tests for verbose option
1 parent 676792a commit f7d8a90

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/util.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ async function e_call(argv, script, ...args) {
212212
return;
213213
}
214214

215+
if (argv.verbose !== undefined &&
216+
// this must exclude NaN -- yargs default value for numeric type
217+
!(argv.verbose >= 0 && argv.verbose <= 5)) {
218+
console.warn("invalid value for --verbose option: must be a number between 0 and 5");
219+
process.exit(1);
220+
return;
221+
}
222+
215223
return new Promise(resolve => {
216224
let _path = el_script(script);
217225

test/jest/options.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ describe("options", () => {
1818
});
1919
});
2020

21+
describe("verbose option", () => {
22+
it("should error if no number is given", async () => {
23+
await expect(ctx.runEask("info -v")).rejects.toMatchObject({ code: 1 });
24+
});
25+
26+
it("should error if the number is omitted before the next option", async () => {
27+
await expect(ctx.runEask("info -v --no-color")).rejects.toMatchObject({
28+
code: 1,
29+
});
30+
});
31+
});
32+
2133
test.each([
2234
"-a",
2335
"--all",

0 commit comments

Comments
 (0)