refactor(cli): extract shared command-removal and timeout action helpers

This commit is contained in:
Peter Steinberger
2026-02-21 20:18:00 +00:00
parent bb490a4b51
commit 944913fc98
5 changed files with 81 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
import type { Command } from "commander";
import { getPrimaryCommand, hasHelpOrVersion } from "../argv.js";
import { reparseProgramFromActionArgs } from "./action-reparse.js";
import { removeCommandByName } from "./command-tree.js";
import type { ProgramContext } from "./context.js";
import { registerSubCliCommands } from "./register.subclis.js";
@@ -229,22 +230,11 @@ export function getCoreCliCommandsWithSubcommands(): string[] {
return collectCoreCliCommandNames((command) => command.hasSubcommands);
}
function removeCommand(program: Command, command: Command) {
const commands = program.commands as Command[];
const index = commands.indexOf(command);
if (index >= 0) {
commands.splice(index, 1);
}
}
function removeEntryCommands(program: Command, entry: CoreCliEntry) {
// Some registrars install multiple top-level commands (e.g. status/health/sessions).
// Remove placeholders/old registrations for all names in the entry before re-registering.
for (const cmd of entry.commands) {
const existing = program.commands.find((c) => c.name() === cmd.name);
if (existing) {
removeCommand(program, existing);
}
removeCommandByName(program, cmd.name);
}
}