Files
hyperframes/packages/cli/src/utils/integerArg.ts
T
DeanandClaude Opus 5.5 559499453b fix(cli): reject bad billing --timeout and --needed values as usage errors (#7910)
* 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>
2026-11-18 16:33:18 +00:00

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;
}