diff --git a/.changeset/clever-eagles-romp.md b/.changeset/clever-eagles-romp.md new file mode 100644 index 000000000..423a3ae27 --- /dev/null +++ b/.changeset/clever-eagles-romp.md @@ -0,0 +1,5 @@ +--- +type: Fixed +pr: 2231 +--- +**`phase complete --phase N` now works alongside the positional form** — the phase verb family treated the first positional as the phase number, so `--phase 12` was passed as the literal phase name and failed with 'Phase --phase not found'. The phase family now accepts the --phase flag consistently with the state family, and unrecognized flags yield a usage error. (#2201) diff --git a/src/phase-command-router.cts b/src/phase-command-router.cts index 86502ec8c..3d4e0822f 100644 --- a/src/phase-command-router.cts +++ b/src/phase-command-router.cts @@ -163,7 +163,28 @@ function routePhaseCommand({ phase, args, cwd, raw, error }: RoutePhaseCommandOp return { ok: true as const, data: null }; }, complete: (_ctx: Record): { ok: true; data: null } => { - phase.cmdPhaseComplete(cwd, args[2], raw); + // #2201: accept --phase N as well as the positional form (the state + // family already accepts --phase). An unrecognized flag is a usage + // error, not "Phase --phase not found". + let phaseNum: string | null = null; + for (let i = 2; i < args.length; i++) { + if (args[i] === '--phase') { + phaseNum = args[++i]; + if (!phaseNum || phaseNum.startsWith('--')) + return makeInvalidArgs('--phase', '--phase requires a value') as never; + } else if (args[i].startsWith('--phase=')) { + phaseNum = args[i].slice(8); + } else if (args[i] === '--raw') { + continue; + } else if (args[i].startsWith('--')) { + return makeInvalidArgs(args[i], `phase complete does not support ${args[i]}`) as never; + } else { + phaseNum = args[i]; + } + } + if (!phaseNum) + return makeInvalidArgs('--phase', 'phase number required (positional or --phase N)') as never; + phase.cmdPhaseComplete(cwd, phaseNum, raw); return { ok: true as const, data: null }; }, 'uat-passed': (_ctx: Record): { ok: true; data: null } => { @@ -185,7 +206,26 @@ function routePhaseCommand({ phase, args, cwd, raw, error }: RoutePhaseCommandOp }, // #1437 — list plan files for a phase 'list-plans': (_ctx: Record): { ok: true; data: null } => { - phase.cmdPhaseListPlans(cwd, args[2], raw); + // #2201: accept --phase N as well as positional. + let phaseNum: string | null = null; + for (let i = 2; i < args.length; i++) { + if (args[i] === '--phase') { + phaseNum = args[++i]; + if (!phaseNum || phaseNum.startsWith('--')) + return makeInvalidArgs('--phase', '--phase requires a value') as never; + } else if (args[i].startsWith('--phase=')) { + phaseNum = args[i].slice(8); + } else if (args[i] === '--raw') { + continue; + } else if (args[i].startsWith('--')) { + return makeInvalidArgs(args[i], `phase list-plans does not support ${args[i]}`) as never; + } else { + phaseNum = args[i]; + } + } + if (!phaseNum) + return makeInvalidArgs('--phase', 'phase number required (positional or --phase N)') as never; + phase.cmdPhaseListPlans(cwd, phaseNum, raw); return { ok: true as const, data: null }; }, },