From 8ab90858baabf766784481b09b2c5a11252a744c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 18 Feb 2026 17:22:31 +0000 Subject: [PATCH] refactor(auto-reply): share command action arg formatting --- src/auto-reply/commands-args.ts | 49 ++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/auto-reply/commands-args.ts b/src/auto-reply/commands-args.ts index 6acd22a4cdb..ab49b9ea68a 100644 --- a/src/auto-reply/commands-args.ts +++ b/src/auto-reply/commands-args.ts @@ -22,33 +22,44 @@ function normalizeArgValue(value: unknown): string | 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 path = normalizeArgValue(values.path); const value = normalizeArgValue(values.value); if (!action) { return undefined; } - const rest = formatSetUnsetArgAction(action, { path, value }); - if (action === "show" || action === "get") { - return path ? `${action} ${path}` : action; + const knownAction = params.formatKnownAction(action, path); + if (knownAction) { + return knownAction; } - return rest; -}; + return formatSetUnsetArgAction(action, { path, value }); +} -const formatDebugArgs: CommandArgsFormatter = (values) => { - const action = normalizeArgValue(values.action)?.toLowerCase(); - const path = normalizeArgValue(values.path); - const value = normalizeArgValue(values.value); - if (!action) { - return undefined; - } - const rest = formatSetUnsetArgAction(action, { path, value }); - if (action === "show" || action === "reset") { - return action; - } - return rest; -}; +const formatConfigArgs: CommandArgsFormatter = (values) => + formatActionArgs(values, { + formatKnownAction: (action, path) => { + if (action === "show" || action === "get") { + return path ? `${action} ${path}` : action; + } + return undefined; + }, + }); + +const formatDebugArgs: CommandArgsFormatter = (values) => + formatActionArgs(values, { + formatKnownAction: (action) => { + if (action === "show" || action === "reset") { + return action; + } + return undefined; + }, + }); function formatSetUnsetArgAction( action: string,