mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 10:41:23 +00:00
refactor: share cli startup and routing helpers
This commit is contained in:
38
src/cli/command-bootstrap.ts
Normal file
38
src/cli/command-bootstrap.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
ensureCliPluginRegistryLoaded,
|
||||
resolvePluginRegistryScopeForCommandPath,
|
||||
} from "./plugin-registry-loader.js";
|
||||
|
||||
let configGuardModulePromise: Promise<typeof import("./program/config-guard.js")> | undefined;
|
||||
|
||||
function loadConfigGuardModule() {
|
||||
configGuardModulePromise ??= import("./program/config-guard.js");
|
||||
return configGuardModulePromise;
|
||||
}
|
||||
|
||||
export async function ensureCliCommandBootstrap(params: {
|
||||
runtime: RuntimeEnv;
|
||||
commandPath: string[];
|
||||
suppressDoctorStdout?: boolean;
|
||||
skipConfigGuard?: boolean;
|
||||
allowInvalid?: boolean;
|
||||
loadPlugins?: boolean;
|
||||
}) {
|
||||
if (!params.skipConfigGuard) {
|
||||
const { ensureConfigReady } = await loadConfigGuardModule();
|
||||
await ensureConfigReady({
|
||||
runtime: params.runtime,
|
||||
commandPath: params.commandPath,
|
||||
...(params.allowInvalid ? { allowInvalid: true } : {}),
|
||||
...(params.suppressDoctorStdout ? { suppressDoctorStdout: true } : {}),
|
||||
});
|
||||
}
|
||||
if (!params.loadPlugins) {
|
||||
return;
|
||||
}
|
||||
await ensureCliPluginRegistryLoaded({
|
||||
scope: resolvePluginRegistryScopeForCommandPath(params.commandPath),
|
||||
routeLogsToStderr: params.suppressDoctorStdout,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user