mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 15:30:39 +00:00
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { isTruthyEnvValue } from "../infra/env.js";
|
|
import { defaultRuntime } from "../runtime.js";
|
|
import { VERSION } from "../version.js";
|
|
import { getCommandPath, hasHelpOrVersion } from "./argv.js";
|
|
import { emitCliBanner } from "./banner.js";
|
|
import { ensurePluginRegistryLoaded } from "./plugin-registry.js";
|
|
import { ensureConfigReady } from "./program/config-guard.js";
|
|
import { findRoutedCommand } from "./program/routes.js";
|
|
|
|
async function prepareRoutedCommand(params: {
|
|
argv: string[];
|
|
commandPath: string[];
|
|
loadPlugins?: boolean | ((argv: string[]) => boolean);
|
|
}) {
|
|
emitCliBanner(VERSION, { argv: params.argv });
|
|
await ensureConfigReady({ runtime: defaultRuntime, commandPath: params.commandPath });
|
|
const shouldLoadPlugins =
|
|
typeof params.loadPlugins === "function" ? params.loadPlugins(params.argv) : params.loadPlugins;
|
|
if (shouldLoadPlugins) {
|
|
ensurePluginRegistryLoaded();
|
|
}
|
|
}
|
|
|
|
export async function tryRouteCli(argv: string[]): Promise<boolean> {
|
|
if (isTruthyEnvValue(process.env.OPENCLAW_DISABLE_ROUTE_FIRST)) {
|
|
return false;
|
|
}
|
|
if (hasHelpOrVersion(argv)) {
|
|
return false;
|
|
}
|
|
|
|
const path = getCommandPath(argv, 2);
|
|
if (!path[0]) {
|
|
return false;
|
|
}
|
|
const route = findRoutedCommand(path);
|
|
if (!route) {
|
|
return false;
|
|
}
|
|
await prepareRoutedCommand({ argv, commandPath: path, loadPlugins: route.loadPlugins });
|
|
return route.run(argv);
|
|
}
|