@@ -24,8 +24,8 @@ import {
2424 type InteractionPathId ,
2525} from '../../src/contracts/interaction-guarantees.ts' ;
2626import { DAEMON_COMMAND_DESCRIPTORS } from '../../src/daemon/daemon-command-registry.ts' ;
27+ import { parseArgs } from 'node:util' ;
2728import { selectChecks , type CheckPlan } from '../check-affected/model.ts' ;
28- import { parseScriptArgs } from '../lib/cli-args.ts' ;
2929import {
3030 bound ,
3131 collectDependents ,
@@ -80,18 +80,33 @@ export type BlastRadius = {
8080 guaranteeRows : GuaranteeRow [ ] ;
8181} ;
8282
83- function parseInvocation ( argv : readonly string [ ] ) : { file : string ; json : boolean ; limit : number } {
84- const positionals = argv . filter ( ( arg ) => ! arg . startsWith ( '-' ) ) ;
85- const flags = argv . filter ( ( arg ) => arg . startsWith ( '-' ) ) ;
86- const values = parseScriptArgs ( flags , USAGE , {
87- json : { type : 'boolean' , default : false } ,
88- limit : { type : 'string' , default : '10' } ,
83+ export type Invocation = { file : string ; json : boolean ; limit : number } | { help : true } ;
84+
85+ /**
86+ * `parseArgs` with positionals enabled rather than the shared `parseScriptArgs` helper, which
87+ * rejects them: partitioning argv by a leading dash would detach `--limit` from its value.
88+ */
89+ export function parseInvocation ( argv : readonly string [ ] ) : Invocation {
90+ const { values, positionals } = parseArgs ( {
91+ args : [ ...argv ] ,
92+ options : {
93+ json : { type : 'boolean' , default : false } ,
94+ limit : { type : 'string' , default : '10' } ,
95+ help : { type : 'boolean' , short : 'h' , default : false } ,
96+ } ,
97+ allowPositionals : true ,
8998 } ) ;
99+ if ( values . help ) return { help : true } ;
100+
90101 const target = positionals [ 0 ] ;
91102 if ( target === undefined ) throw new Error ( `missing <path>.\n${ USAGE } ` ) ;
92- if ( positionals . length > 1 ) throw new Error ( `expected one <path>, got ${ positionals . length } .` ) ;
103+ if ( positionals . length > 1 ) {
104+ throw new Error ( `expected one <path>, got ${ positionals . length } : ${ positionals . join ( ' ' ) } ` ) ;
105+ }
93106 const limit = Number ( values . limit ) ;
94- if ( ! Number . isInteger ( limit ) || limit < 1 ) throw new Error ( `--limit must be a positive integer` ) ;
107+ if ( ! Number . isInteger ( limit ) || limit < 1 ) {
108+ throw new Error ( `--limit must be a positive integer, got "${ values . limit } "` ) ;
109+ }
95110 return { file : target , json : Boolean ( values . json ) , limit } ;
96111}
97112
@@ -266,7 +281,12 @@ export function formatBlastRadius(radius: BlastRadius, limit: number): string {
266281}
267282
268283export async function runAffected ( argv : readonly string [ ] , repoRoot : string ) : Promise < number > {
269- const { file, json, limit } = parseInvocation ( argv ) ;
284+ const invocation = parseInvocation ( argv ) ;
285+ if ( 'help' in invocation ) {
286+ process . stdout . write ( USAGE ) ;
287+ return 0 ;
288+ }
289+ const { file, json, limit } = invocation ;
270290 const radius = await computeBlastRadius ( repoRoot , normalizeTarget ( file , repoRoot ) ) ;
271291 process . stdout . write (
272292 json ? `${ JSON . stringify ( radius , null , 2 ) } \n` : formatBlastRadius ( radius , limit ) ,
0 commit comments