mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-10-03 21:27:07 +00:00
fix(cli): validate positive numeric options (#49)
This commit is contained in:
parent
aa3fdba277
commit
fbf4d76372
3 changed files with 37 additions and 8 deletions
9
packages/cli/src/numeric-options.ts
Normal file
9
packages/cli/src/numeric-options.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { InvalidArgumentError } from "commander";
|
||||
|
||||
export function parsePositiveInteger(value: string): number {
|
||||
const parsed = Number(value);
|
||||
if (value.trim() === "" || !Number.isSafeInteger(parsed) || parsed < 1) {
|
||||
throw new InvalidArgumentError("must be a positive integer");
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue