refactor(cmdline): run the program's own commander action instead of a plan callback

parseCmdline(ctx, program): void only adapts commander control flow to
the launcher: it parses the immutable cmdlineArgs snapshot and turns
help, version, parse errors, and action rejections into a ctx.appExit
request. App validation and the ctx.provide of the app-owned service
live in the program's own synchronous .action(), which commander runs
inside parse — program.error(...) there shares the exit path with a
grammar rejection. Deletes the CmdlinePlan export, its unread ctx
parameter, the type-unsound (() => ({}) as T) default, and the
T | undefined return with its per-caller publish guard.
This commit is contained in:
Turtle
2026-08-11 18:41:21 +08:00
parent 8e1c1faaad
commit 54dd75a969
17 changed files with 229 additions and 116 deletions

View File

@@ -227,8 +227,8 @@ function createStartupFixture(): StartupFixture {
"export const inject = ['cmdlineArgs']",
'export function apply(ctx) {',
" const program = new Command().name('fixture').option('--generation <value>', 'echoed generation')",
' const values = parseCmdline(ctx, program, parsed => ({ generation: parsed.opts().generation }))',
' if (values !== undefined) ctx.provide(\'fixtureStartup\', values)',
" program.action(() => ctx.provide('fixtureStartup', { generation: program.opts().generation }))",
' parseCmdline(ctx, program)',
'}',
'',
].join('\n'))