@@ -16,6 +16,7 @@ import {
1616 type QaEvidenceSummaryJson ,
1717} from "../extensions/qa-lab/api.js" ;
1818import type { AgentExecEnvelope } from "../src/commands/agent-exec.ts" ;
19+ import { requireOptionArgument } from "./lib/arg-utils.mts" ;
1920import { previewForDevToolLog , redactJsonValueForDevToolLog } from "./lib/dev-tooling-safety.ts" ;
2021
2122export { validateQaEvidenceSummaryJson } ;
@@ -164,14 +165,6 @@ Provider credentials are read from the environment and are never written to arti
164165` ;
165166}
166167
167- function readOptionValue ( argv : readonly string [ ] , index : number , flag : string ) : string {
168- const value = argv [ index + 1 ] ;
169- if ( ! value || value . startsWith ( "-" ) ) {
170- throw new Error ( `${ flag } requires a value` ) ;
171- }
172- return value ;
173- }
174-
175168function parseIntegerOption ( raw : string , flag : string , max ?: number ) : number {
176169 if ( ! / ^ \d + $ / u. test ( raw ) ) {
177170 throw new Error ( `${ flag } must be a positive integer` ) ;
@@ -230,7 +223,7 @@ export function parseCodeModeMatrixOptions(
230223 for ( let index = 0 ; index < argv . length ; index += 1 ) {
231224 const arg = argv [ index ] ;
232225 if ( arg === "--model" ) {
233- const value = readOptionValue ( argv , index , arg ) . trim ( ) ;
226+ const value = requireOptionArgument ( argv , index , arg ) . trim ( ) ;
234227 if ( ! value . includes ( "/" ) ) {
235228 throw new Error (
236229 `--model must use a provider/model reference; got ${ JSON . stringify ( value ) } ` ,
@@ -241,36 +234,40 @@ export function parseCodeModeMatrixOptions(
241234 continue ;
242235 }
243236 if ( arg === "--mode" ) {
244- collectUnique ( modes , parseMode ( readOptionValue ( argv , index , arg ) ) , arg ) ;
237+ collectUnique ( modes , parseMode ( requireOptionArgument ( argv , index , arg ) ) , arg ) ;
245238 index += 1 ;
246239 continue ;
247240 }
248241 if ( arg === "--task" ) {
249- collectUnique ( tasks , parseTask ( readOptionValue ( argv , index , arg ) ) , arg ) ;
242+ collectUnique ( tasks , parseTask ( requireOptionArgument ( argv , index , arg ) ) , arg ) ;
250243 index += 1 ;
251244 continue ;
252245 }
253246 if ( arg === "--repetitions" ) {
254247 recordOnce ( arg ) ;
255- repetitions = parseIntegerOption ( readOptionValue ( argv , index , arg ) , arg , MAX_REPETITIONS ) ;
248+ repetitions = parseIntegerOption (
249+ requireOptionArgument ( argv , index , arg ) ,
250+ arg ,
251+ MAX_REPETITIONS ,
252+ ) ;
256253 index += 1 ;
257254 continue ;
258255 }
259256 if ( arg === "--timeout" ) {
260257 recordOnce ( arg ) ;
261- timeoutSeconds = parseIntegerOption ( readOptionValue ( argv , index , arg ) , arg ) ;
258+ timeoutSeconds = parseIntegerOption ( requireOptionArgument ( argv , index , arg ) , arg ) ;
262259 index += 1 ;
263260 continue ;
264261 }
265262 if ( arg === "--thinking" ) {
266263 recordOnce ( arg ) ;
267- thinking = readOptionValue ( argv , index , arg ) . trim ( ) ;
264+ thinking = requireOptionArgument ( argv , index , arg ) . trim ( ) ;
268265 index += 1 ;
269266 continue ;
270267 }
271268 if ( arg === "--output-dir" ) {
272269 recordOnce ( arg ) ;
273- outputDir = readOptionValue ( argv , index , arg ) ;
270+ outputDir = requireOptionArgument ( argv , index , arg ) ;
274271 index += 1 ;
275272 continue ;
276273 }
0 commit comments