mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 08:11:38 +00:00
perf(cli): speed up help/config paths and route config get/unset
This commit is contained in:
@@ -24,6 +24,24 @@ export function rewriteUpdateFlagArgv(argv: string[]): string[] {
|
||||
return next;
|
||||
}
|
||||
|
||||
export function shouldRegisterPrimarySubcommand(argv: string[]): boolean {
|
||||
return !hasHelpOrVersion(argv);
|
||||
}
|
||||
|
||||
export function shouldSkipPluginCommandRegistration(params: {
|
||||
argv: string[];
|
||||
primary: string | null;
|
||||
hasBuiltinPrimary: boolean;
|
||||
}): boolean {
|
||||
if (!hasHelpOrVersion(params.argv)) {
|
||||
return false;
|
||||
}
|
||||
if (!params.primary) {
|
||||
return true;
|
||||
}
|
||||
return params.hasBuiltinPrimary;
|
||||
}
|
||||
|
||||
export async function runCli(argv: string[] = process.argv) {
|
||||
const normalizedArgv = stripWindowsNodeExec(argv);
|
||||
loadDotEnv({ quiet: true });
|
||||
@@ -55,12 +73,18 @@ export async function runCli(argv: string[] = process.argv) {
|
||||
const parseArgv = rewriteUpdateFlagArgv(normalizedArgv);
|
||||
// Register the primary subcommand if one exists (for lazy-loading)
|
||||
const primary = getPrimaryCommand(parseArgv);
|
||||
if (primary) {
|
||||
if (primary && shouldRegisterPrimarySubcommand(parseArgv)) {
|
||||
const { registerSubCliByName } = await import("./program/register.subclis.js");
|
||||
await registerSubCliByName(program, primary);
|
||||
}
|
||||
|
||||
const shouldSkipPluginRegistration = !primary && hasHelpOrVersion(parseArgv);
|
||||
const hasBuiltinPrimary =
|
||||
primary !== null && program.commands.some((command) => command.name() === primary);
|
||||
const shouldSkipPluginRegistration = shouldSkipPluginCommandRegistration({
|
||||
argv: parseArgv,
|
||||
primary,
|
||||
hasBuiltinPrimary,
|
||||
});
|
||||
if (!shouldSkipPluginRegistration) {
|
||||
// Register plugin CLI commands before parsing
|
||||
const { registerPluginCliCommands } = await import("../plugins/cli.js");
|
||||
|
||||
Reference in New Issue
Block a user