mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
fix(cli): preserve routed command arg typing
This commit is contained in:
@@ -5,6 +5,12 @@ export type CommandPathMatchRule =
|
||||
exact?: boolean;
|
||||
};
|
||||
|
||||
function isStructuredCommandPathMatchRule(
|
||||
rule: CommandPathMatchRule,
|
||||
): rule is Extract<CommandPathMatchRule, { pattern: readonly string[] }> {
|
||||
return !Array.isArray(rule);
|
||||
}
|
||||
|
||||
export function matchesCommandPath(
|
||||
commandPath: string[],
|
||||
pattern: readonly string[],
|
||||
@@ -17,7 +23,7 @@ export function matchesCommandPath(
|
||||
}
|
||||
|
||||
export function matchesCommandPathRule(commandPath: string[], rule: CommandPathMatchRule): boolean {
|
||||
if (Array.isArray(rule)) {
|
||||
if (!isStructuredCommandPathMatchRule(rule)) {
|
||||
return matchesCommandPath(commandPath, rule);
|
||||
}
|
||||
return matchesCommandPath(commandPath, rule.pattern, { exact: rule.exact });
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import type { CliRoutedCommandId } from "../command-catalog.js";
|
||||
import {
|
||||
parseAgentsListRouteArgs,
|
||||
parseConfigGetRouteArgs,
|
||||
@@ -17,15 +16,21 @@ export type RoutedCommandDefinition<TArgs = unknown> = {
|
||||
runParsedArgs: (args: TArgs) => Promise<void>;
|
||||
};
|
||||
|
||||
export const routedCommandDefinitions: Record<CliRoutedCommandId, RoutedCommandDefinition> = {
|
||||
health: {
|
||||
function defineRoutedCommand<TArgs>(
|
||||
definition: RoutedCommandDefinition<TArgs>,
|
||||
): RoutedCommandDefinition<TArgs> {
|
||||
return definition;
|
||||
}
|
||||
|
||||
export const routedCommandDefinitions = {
|
||||
health: defineRoutedCommand({
|
||||
parseArgs: parseHealthRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { healthCommand } = await import("../../commands/health.js");
|
||||
await healthCommand(args, defaultRuntime);
|
||||
},
|
||||
},
|
||||
status: {
|
||||
}),
|
||||
status: defineRoutedCommand({
|
||||
parseArgs: parseStatusRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
if (args.json) {
|
||||
@@ -44,54 +49,54 @@ export const routedCommandDefinitions: Record<CliRoutedCommandId, RoutedCommandD
|
||||
const { statusCommand } = await import("../../commands/status.js");
|
||||
await statusCommand(args, defaultRuntime);
|
||||
},
|
||||
},
|
||||
"gateway-status": {
|
||||
}),
|
||||
"gateway-status": defineRoutedCommand({
|
||||
parseArgs: parseGatewayStatusRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { runDaemonStatus } = await import("../daemon-cli/status.js");
|
||||
await runDaemonStatus(args);
|
||||
},
|
||||
},
|
||||
sessions: {
|
||||
}),
|
||||
sessions: defineRoutedCommand({
|
||||
parseArgs: parseSessionsRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { sessionsCommand } = await import("../../commands/sessions.js");
|
||||
await sessionsCommand(args, defaultRuntime);
|
||||
},
|
||||
},
|
||||
"agents-list": {
|
||||
}),
|
||||
"agents-list": defineRoutedCommand({
|
||||
parseArgs: parseAgentsListRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { agentsListCommand } = await import("../../commands/agents.js");
|
||||
await agentsListCommand(args, defaultRuntime);
|
||||
},
|
||||
},
|
||||
"config-get": {
|
||||
}),
|
||||
"config-get": defineRoutedCommand({
|
||||
parseArgs: parseConfigGetRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { runConfigGet } = await import("../config-cli.js");
|
||||
await runConfigGet(args);
|
||||
},
|
||||
},
|
||||
"config-unset": {
|
||||
}),
|
||||
"config-unset": defineRoutedCommand({
|
||||
parseArgs: parseConfigUnsetRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { runConfigUnset } = await import("../config-cli.js");
|
||||
await runConfigUnset(args);
|
||||
},
|
||||
},
|
||||
"models-list": {
|
||||
}),
|
||||
"models-list": defineRoutedCommand({
|
||||
parseArgs: parseModelsListRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { modelsListCommand } = await import("../../commands/models.js");
|
||||
await modelsListCommand(args, defaultRuntime);
|
||||
},
|
||||
},
|
||||
"models-status": {
|
||||
}),
|
||||
"models-status": defineRoutedCommand({
|
||||
parseArgs: parseModelsStatusRouteArgs,
|
||||
runParsedArgs: async (args) => {
|
||||
const { modelsStatusCommand } = await import("../../commands/models.js");
|
||||
await modelsStatusCommand(args, defaultRuntime);
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user