11import type { BatchStep } from '../client-types.ts' ;
22import { readInputFromCli } from '../commands/cli-grammar.ts' ;
3+ import { isCommandName , type CommandName } from '../commands/command-surface.ts' ;
34import type { CliFlags } from '../utils/command-schema.ts' ;
45import { AppError } from '../utils/errors.ts' ;
56
67type LegacyCliBatchStep = {
7- command : string ;
8+ command : CommandName ;
89 positionals ?: string [ ] ;
910 flags ?: Record < string , unknown > ;
1011 runtime ?: unknown ;
@@ -69,8 +70,7 @@ function readLegacyCliBatchStep(step: unknown, stepNumber: number): LegacyCliBat
6970 }
7071 const record = step as Record < string , unknown > ;
7172 assertLegacyBatchStepKeys ( record , stepNumber ) ;
72- const command = typeof record . command === 'string' ? record . command . trim ( ) . toLowerCase ( ) : '' ;
73- if ( ! command ) throw new AppError ( 'INVALID_ARGS' , `Batch step ${ stepNumber } requires command.` ) ;
73+ const command = readLegacyCommand ( record . command , stepNumber ) ;
7474 const positionals = readLegacyPositionals ( record . positionals , stepNumber ) ;
7575 const flags = readLegacyFlags ( record . flags , stepNumber ) ;
7676 return {
@@ -81,6 +81,16 @@ function readLegacyCliBatchStep(step: unknown, stepNumber: number): LegacyCliBat
8181 } ;
8282}
8383
84+ function readLegacyCommand ( value : unknown , stepNumber : number ) : CommandName {
85+ const command = typeof value === 'string' ? value . trim ( ) . toLowerCase ( ) : '' ;
86+ if ( ! command ) throw new AppError ( 'INVALID_ARGS' , `Batch step ${ stepNumber } requires command.` ) ;
87+ if ( isCommandName ( command ) ) return command ;
88+ throw new AppError (
89+ 'INVALID_ARGS' ,
90+ `Batch step ${ stepNumber } command is not available through command batch: ${ String ( value ) } ` ,
91+ ) ;
92+ }
93+
8494function assertLegacyBatchStepKeys ( record : Record < string , unknown > , stepNumber : number ) : void {
8595 const unknownKeys = Object . keys ( record ) . filter (
8696 ( key ) => ! [ 'command' , 'positionals' , 'flags' , 'runtime' ] . includes ( key ) ,
0 commit comments