refactor(auto-reply): dedupe command arg formatting

This commit is contained in:
Peter Steinberger
2026-02-15 06:51:29 +00:00
parent a39a5a35b0
commit ceacc2675d

View File

@@ -29,22 +29,11 @@ const formatConfigArgs: CommandArgsFormatter = (values) => {
if (!action) { if (!action) {
return undefined; return undefined;
} }
const rest = formatSetUnsetArgAction(action, { path, value });
if (action === "show" || action === "get") { if (action === "show" || action === "get") {
return path ? `${action} ${path}` : action; return path ? `${action} ${path}` : action;
} }
if (action === "unset") { return rest;
return path ? `${action} ${path}` : action;
}
if (action === "set") {
if (!path) {
return action;
}
if (!value) {
return `${action} ${path}`;
}
return `${action} ${path}=${value}`;
}
return action;
}; };
const formatDebugArgs: CommandArgsFormatter = (values) => { const formatDebugArgs: CommandArgsFormatter = (values) => {
@@ -54,23 +43,31 @@ const formatDebugArgs: CommandArgsFormatter = (values) => {
if (!action) { if (!action) {
return undefined; return undefined;
} }
const rest = formatSetUnsetArgAction(action, { path, value });
if (action === "show" || action === "reset") { if (action === "show" || action === "reset") {
return action; return action;
} }
return rest;
};
function formatSetUnsetArgAction(
action: string,
params: { path: string | undefined; value: string | undefined },
): string {
if (action === "unset") { if (action === "unset") {
return path ? `${action} ${path}` : action; return params.path ? `${action} ${params.path}` : action;
} }
if (action === "set") { if (action === "set") {
if (!path) { if (!params.path) {
return action; return action;
} }
if (!value) { if (!params.value) {
return `${action} ${path}`; return `${action} ${params.path}`;
} }
return `${action} ${path}=${value}`; return `${action} ${params.path}=${params.value}`;
} }
return action; return action;
}; }
const formatQueueArgs: CommandArgsFormatter = (values) => { const formatQueueArgs: CommandArgsFormatter = (values) => {
const mode = normalizeArgValue(values.mode); const mode = normalizeArgValue(values.mode);