@@ -69,9 +69,19 @@ function phaseDetail(label: string, result: ScaffoldResult): string {
6969// ─── Command ────────────────────────────────────────────────
7070
7171export async function runCommand ( options : CLIOptions , args : string [ ] ) : Promise < number > {
72- // Parse description
72+ // Parse flags first (getFlag consumes flag + value from args)
7373 const filePath = getFlag ( args , '--file' ) ;
74- const positional = args . filter ( a => ! a . startsWith ( '-' ) && a !== filePath ) ;
74+ const outputDir = getFlag ( args , '--output' ) ;
75+ const seedStr = getFlag ( args , '--seed' ) ;
76+ const urlOverride = getFlag ( args , '--url' ) ;
77+ const fwOverride = getFlag ( args , '--framework' ) ;
78+ const dbOverride = getFlag ( args , '--database' ) ;
79+
80+ // Collect flag values to exclude from positional args
81+ const flagValues = new Set ( [ filePath , outputDir , seedStr , urlOverride , fwOverride , dbOverride ] . filter ( Boolean ) ) ;
82+
83+ // Parse description from remaining positional args
84+ const positional = args . filter ( a => ! a . startsWith ( '-' ) && ! flagValues . has ( a ) ) ;
7585 let description : string ;
7686
7787 if ( filePath ) {
@@ -85,14 +95,12 @@ export async function runCommand(options: CLIOptions, args: string[]): Promise<n
8595
8696 if ( ! description ) throw new CLIError ( 'Empty description.' ) ;
8797
88- // Parse flags
89- const seedStr = getFlag ( args , '--seed' ) ;
90- const outputDir = getFlag ( args , '--output' ) ?? `./${ slugify ( description ) } ` ;
98+ const resolvedOutput = outputDir ?? `./${ slugify ( description ) } ` ;
9199 const dryRun = args . includes ( '--dry-run' ) ;
92100
93101 // Engine client
94102 const creds = loadCredentials ( ) ;
95- const baseUrl = getFlag ( args , '--url' ) ;
103+ const baseUrl = urlOverride ;
96104 const client = new EngineClient ( { baseUrl : baseUrl ?? creds ?. baseUrl , apiKey : creds ?. apiKey } ) ;
97105
98106 // Determine path: gateway (with API key) or engine fallback
@@ -112,10 +120,8 @@ export async function runCommand(options: CLIOptions, args: string[]): Promise<n
112120 // Engine fallback — basic scaffold
113121 const request : BuildRequest = { description, constraints : { } } ;
114122 if ( args . includes ( '--cloudflare-only' ) ) request . constraints ! . cloudflareOnly = true ;
115- const fw = getFlag ( args , '--framework' ) ;
116- if ( fw ) request . constraints ! . framework = fw ;
117- const db = getFlag ( args , '--database' ) ;
118- if ( db ) request . constraints ! . database = db ;
123+ if ( fwOverride ) request . constraints ! . framework = fwOverride ;
124+ if ( dbOverride ) request . constraints ! . database = dbOverride ;
119125 if ( seedStr ) request . seed = parseInt ( seedStr , 10 ) ;
120126
121127 scaffoldPromise = client . build ( request ) . then ( r => ( {
@@ -130,9 +136,9 @@ export async function runCommand(options: CLIOptions, args: string[]): Promise<n
130136 // JSON mode — no animation
131137 if ( options . format === 'json' ) {
132138 const result = await scaffoldPromise ;
133- console . log ( JSON . stringify ( { ...result , outputDir, dryRun } , null , 2 ) ) ;
139+ console . log ( JSON . stringify ( { ...result , outputDir : resolvedOutput , dryRun } , null , 2 ) ) ;
134140 if ( ! dryRun ) {
135- writeFiles ( outputDir , result . files ) ;
141+ writeFiles ( resolvedOutput , result . files ) ;
136142 }
137143 return EXIT_CODE . SUCCESS ;
138144 }
@@ -188,15 +194,15 @@ export async function runCommand(options: CLIOptions, args: string[]): Promise<n
188194
189195 console . log ( '' ) ;
190196 if ( dryRun ) {
191- console . log ( ` → ${ result . files . length } files would be scaffolded to ${ outputDir } /` ) ;
197+ console . log ( ` → ${ result . files . length } files would be scaffolded to ${ resolvedOutput } /` ) ;
192198 for ( const f of result . files ) {
193199 console . log ( ` ${ f . path } ` ) ;
194200 }
195201 console . log ( '' ) ;
196202 console . log ( ' (dry run — no files written)' ) ;
197203 } else {
198- writeFiles ( outputDir , result . files ) ;
199- console . log ( ` → ${ result . files . length } files scaffolded to ${ outputDir } /` ) ;
204+ writeFiles ( resolvedOutput , result . files ) ;
205+ console . log ( ` → ${ result . files . length } files scaffolded to ${ resolvedOutput } /` ) ;
200206 console . log ( ` → Architecture governed · seed: ${ result . seed ?? 'deterministic' } ` ) ;
201207 if ( result . nextSteps && result . nextSteps . length > 0 ) {
202208 console . log ( '' ) ;
0 commit comments