mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:22:47 +00:00
refactor(auto-reply): share command action arg formatting
This commit is contained in:
@@ -22,33 +22,44 @@ function normalizeArgValue(value: unknown): string | undefined {
|
|||||||
return text ? text : undefined;
|
return text ? text : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatConfigArgs: CommandArgsFormatter = (values) => {
|
function formatActionArgs(
|
||||||
|
values: CommandArgValues,
|
||||||
|
params: {
|
||||||
|
formatKnownAction: (action: string, path: string | undefined) => string | undefined;
|
||||||
|
},
|
||||||
|
): string | undefined {
|
||||||
const action = normalizeArgValue(values.action)?.toLowerCase();
|
const action = normalizeArgValue(values.action)?.toLowerCase();
|
||||||
const path = normalizeArgValue(values.path);
|
const path = normalizeArgValue(values.path);
|
||||||
const value = normalizeArgValue(values.value);
|
const value = normalizeArgValue(values.value);
|
||||||
if (!action) {
|
if (!action) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const rest = formatSetUnsetArgAction(action, { path, value });
|
const knownAction = params.formatKnownAction(action, path);
|
||||||
if (action === "show" || action === "get") {
|
if (knownAction) {
|
||||||
return path ? `${action} ${path}` : action;
|
return knownAction;
|
||||||
}
|
}
|
||||||
return rest;
|
return formatSetUnsetArgAction(action, { path, value });
|
||||||
};
|
}
|
||||||
|
|
||||||
const formatDebugArgs: CommandArgsFormatter = (values) => {
|
const formatConfigArgs: CommandArgsFormatter = (values) =>
|
||||||
const action = normalizeArgValue(values.action)?.toLowerCase();
|
formatActionArgs(values, {
|
||||||
const path = normalizeArgValue(values.path);
|
formatKnownAction: (action, path) => {
|
||||||
const value = normalizeArgValue(values.value);
|
if (action === "show" || action === "get") {
|
||||||
if (!action) {
|
return path ? `${action} ${path}` : action;
|
||||||
return undefined;
|
}
|
||||||
}
|
return undefined;
|
||||||
const rest = formatSetUnsetArgAction(action, { path, value });
|
},
|
||||||
if (action === "show" || action === "reset") {
|
});
|
||||||
return action;
|
|
||||||
}
|
const formatDebugArgs: CommandArgsFormatter = (values) =>
|
||||||
return rest;
|
formatActionArgs(values, {
|
||||||
};
|
formatKnownAction: (action) => {
|
||||||
|
if (action === "show" || action === "reset") {
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function formatSetUnsetArgAction(
|
function formatSetUnsetArgAction(
|
||||||
action: string,
|
action: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user