refactor(cli): share commander reparse helper

This commit is contained in:
Peter Steinberger
2026-02-15 14:02:18 +00:00
parent 42b0d6f43e
commit 384a886b70
3 changed files with 28 additions and 30 deletions

View File

@@ -0,0 +1,22 @@
import type { Command } from "commander";
import { buildParseArgv } from "../argv.js";
import { resolveActionArgs } from "./helpers.js";
export async function reparseProgramFromActionArgs(
program: Command,
actionArgs: unknown[],
): Promise<void> {
const actionCommand = actionArgs.at(-1) as Command | undefined;
const root = actionCommand?.parent ?? program;
const rawArgs = (root as Command & { rawArgs?: string[] }).rawArgs;
const actionArgsList = resolveActionArgs(actionCommand);
const fallbackArgv = actionCommand?.name()
? [actionCommand.name(), ...actionArgsList]
: actionArgsList;
const parseArgv = buildParseArgv({
programName: program.name(),
rawArgs,
fallbackArgv,
});
await program.parseAsync(parseArgv);
}