@@ -38,6 +38,10 @@ import type {
3838 ImageGenerationBackground ,
3939 ImageGenerationOutputFormat ,
4040} from "../image-generation/types.js" ;
41+ import {
42+ parseStrictFiniteNumber ,
43+ parseStrictPositiveInteger ,
44+ } from "../infra/parse-finite-number.js" ;
4145import { buildMediaUnderstandingRegistry } from "../media-understanding/provider-registry.js" ;
4246import type { RunMediaUnderstandingFileResult } from "../media-understanding/runtime-types.js" ;
4347import {
@@ -1156,13 +1160,24 @@ function parseOptionalFiniteNumber(
11561160 if ( raw === undefined || ( typeof raw === "string" && raw . trim ( ) === "" ) ) {
11571161 return undefined ;
11581162 }
1159- const value = Number ( raw ) ;
1160- if ( ! Number . isFinite ( value ) ) {
1163+ const value = parseStrictFiniteNumber ( raw ) ;
1164+ if ( value === undefined ) {
11611165 throw new Error ( `${ label } must be a finite number` ) ;
11621166 }
11631167 return value ;
11641168}
11651169
1170+ function parseOptionalPositiveInteger ( raw : unknown , label : string ) : number | undefined {
1171+ if ( raw === undefined || ( typeof raw === "string" && raw . trim ( ) === "" ) ) {
1172+ return undefined ;
1173+ }
1174+ const value = parseStrictPositiveInteger ( raw ) ;
1175+ if ( value === undefined ) {
1176+ throw new Error ( `${ label } must be a positive integer` ) ;
1177+ }
1178+ return value ;
1179+ }
1180+
11661181function normalizeImageOutputFormat (
11671182 raw : string | undefined ,
11681183) : ImageGenerationOutputFormat | undefined {
@@ -1933,7 +1948,7 @@ export function registerCapabilityCli(program: Command) {
19331948 capability : "image.generate" ,
19341949 prompt : String ( opts . prompt ) ,
19351950 model : opts . model as string | undefined ,
1936- count : opts . count ? Number . parseInt ( String ( opts . count ) , 10 ) : undefined ,
1951+ count : parseOptionalPositiveInteger ( opts . count , "--count" ) ,
19371952 size : opts . size as string | undefined ,
19381953 aspectRatio : opts . aspectRatio as string | undefined ,
19391954 resolution : opts . resolution as "1K" | "2K" | "4K" | undefined ,
@@ -2410,7 +2425,7 @@ export function registerCapabilityCli(program: Command) {
24102425 const result = await runWebSearchCommand ( {
24112426 query : String ( opts . query ) ,
24122427 provider : opts . provider as string | undefined ,
2413- limit : opts . limit ? Number . parseInt ( String ( opts . limit ) , 10 ) : undefined ,
2428+ limit : parseOptionalPositiveInteger ( opts . limit , "--limit" ) ,
24142429 } ) ;
24152430 emitJsonOrText ( defaultRuntime , Boolean ( opts . json ) , result , formatEnvelopeForText ) ;
24162431 } ) ;
0 commit comments