mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
* fix(cli): reject bad billing --timeout and --needed values as usage errors Closes #7909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(cli): share one positive-integer flag parser across billing, compare and share Refs #7909 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
18 lines
705 B
TypeScript
18 lines
705 B
TypeScript
import { CliUsageError } from "./commandResult.js";
|
|
|
|
/** A whole-number flag from 1 to max; unset returns undefined, anything else is a usage error. */
|
|
export function parsePositiveIntegerArg(
|
|
value: unknown,
|
|
flag: string,
|
|
options: { max?: number; unit?: string } = {},
|
|
): number | undefined {
|
|
if (value === undefined) return undefined;
|
|
const parsed = Number(value);
|
|
const { max, unit } = options;
|
|
if (!Number.isInteger(parsed) || parsed < 1 || (max !== undefined && parsed > max)) {
|
|
const range = max === undefined ? "a positive integer" : `an integer from 1 to ${max}`;
|
|
throw new CliUsageError(`${flag} must be ${range}${unit ? ` number of ${unit}` : ""}`);
|
|
}
|
|
return parsed;
|
|
}
|