mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 06:32:00 +00:00
Plugins: extract CLI lifecycle
This commit is contained in:
@@ -2,6 +2,7 @@ import type { Command } from "commander";
|
||||
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { registerExtensionHostCliCommands } from "../extension-host/cli-lifecycle.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { loadOpenClawPlugins } from "./loader.js";
|
||||
import type { PluginLogger } from "./types.js";
|
||||
@@ -27,38 +28,11 @@ export function registerPluginCliCommands(
|
||||
env,
|
||||
logger,
|
||||
});
|
||||
|
||||
const existingCommands = new Set(program.commands.map((cmd) => cmd.name()));
|
||||
|
||||
for (const entry of registry.cliRegistrars) {
|
||||
if (entry.commands.length > 0) {
|
||||
const overlaps = entry.commands.filter((command) => existingCommands.has(command));
|
||||
if (overlaps.length > 0) {
|
||||
log.debug(
|
||||
`plugin CLI register skipped (${entry.pluginId}): command already registered (${overlaps.join(
|
||||
", ",
|
||||
)})`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const result = entry.register({
|
||||
program,
|
||||
config,
|
||||
workspaceDir,
|
||||
logger,
|
||||
});
|
||||
if (result && typeof result.then === "function") {
|
||||
void result.catch((err) => {
|
||||
log.warn(`plugin CLI register failed (${entry.pluginId}): ${String(err)}`);
|
||||
});
|
||||
}
|
||||
for (const command of entry.commands) {
|
||||
existingCommands.add(command);
|
||||
}
|
||||
} catch (err) {
|
||||
log.warn(`plugin CLI register failed (${entry.pluginId}): ${String(err)}`);
|
||||
}
|
||||
}
|
||||
registerExtensionHostCliCommands({
|
||||
program,
|
||||
registry,
|
||||
config,
|
||||
workspaceDir,
|
||||
logger,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user