mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-16 03:31:10 +00:00
refactor(cli): normalize route boundaries
This commit is contained in:
@@ -4,7 +4,7 @@ import { matchesCommandPath } from "../command-path-matches.js";
|
||||
import { resolveCliCommandPathPolicy } from "../command-path-policy.js";
|
||||
import {
|
||||
routedCommandDefinitions,
|
||||
type RoutedCommandDefinition,
|
||||
type AnyRoutedCommandDefinition,
|
||||
} from "./routed-command-definitions.js";
|
||||
|
||||
export type RouteSpec = {
|
||||
@@ -22,7 +22,7 @@ function createCommandLoadPlugins(commandPath: readonly string[]): (argv: string
|
||||
|
||||
function createParsedRoute(params: {
|
||||
entry: CliCommandCatalogEntry;
|
||||
definition: RoutedCommandDefinition;
|
||||
definition: AnyRoutedCommandDefinition;
|
||||
}): RouteSpec {
|
||||
return {
|
||||
match: (path) =>
|
||||
@@ -51,6 +51,6 @@ export const routedCommands: RouteSpec[] = cliCommandCatalog
|
||||
.map((entry) =>
|
||||
createParsedRoute({
|
||||
entry,
|
||||
definition: routedCommandDefinitions[entry.route.id] as RoutedCommandDefinition,
|
||||
definition: routedCommandDefinitions[entry.route.id],
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -11,16 +11,21 @@ import {
|
||||
parseStatusRouteArgs,
|
||||
} from "./route-args.js";
|
||||
|
||||
export type RoutedCommandDefinition<TArgs = unknown> = {
|
||||
parseArgs: (argv: string[]) => TArgs | null;
|
||||
runParsedArgs: (args: TArgs) => Promise<void>;
|
||||
type RouteArgParser<TArgs> = (argv: string[]) => TArgs | null;
|
||||
|
||||
type ParsedRouteArgs<TParse extends RouteArgParser<unknown>> = Exclude<ReturnType<TParse>, null>;
|
||||
|
||||
export type RoutedCommandDefinition<TParse extends RouteArgParser<unknown>> = {
|
||||
parseArgs: TParse;
|
||||
runParsedArgs: (args: ParsedRouteArgs<TParse>) => Promise<void>;
|
||||
};
|
||||
|
||||
function defineRoutedCommand<TParse extends (argv: string[]) => unknown>(definition: {
|
||||
parseArgs: TParse;
|
||||
runParsedArgs: (args: Exclude<ReturnType<TParse>, null>) => Promise<void>;
|
||||
}): RoutedCommandDefinition<Exclude<ReturnType<TParse>, null>> {
|
||||
return definition as RoutedCommandDefinition<Exclude<ReturnType<TParse>, null>>;
|
||||
export type AnyRoutedCommandDefinition = RoutedCommandDefinition<RouteArgParser<unknown>>;
|
||||
|
||||
function defineRoutedCommand<TParse extends RouteArgParser<unknown>>(
|
||||
definition: RoutedCommandDefinition<TParse>,
|
||||
): RoutedCommandDefinition<TParse> {
|
||||
return definition;
|
||||
}
|
||||
|
||||
export const routedCommandDefinitions = {
|
||||
|
||||
Reference in New Issue
Block a user