refactor(auto-reply): share command action arg formatting

This commit is contained in:
Peter Steinberger
2026-02-18 17:22:31 +00:00
parent 0a78331536
commit 8ab90858ba

View File

@@ -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,