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;
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user