refactor(auto-reply): share set/unset command action parsing

This commit is contained in:
Peter Steinberger
2026-02-18 17:13:40 +00:00
parent 288015a9fc
commit 818419b4c4
4 changed files with 98 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
import { parseSetUnsetCommand } from "./commands-setunset.js";
import { parseSetUnsetCommandAction } from "./commands-setunset.js";
import { parseSlashCommandOrNull } from "./commands-slash-parse.js";
export type ConfigCommand =
@@ -18,22 +18,23 @@ export function parseConfigCommand(raw: string): ConfigCommand | null {
return { action: "error", message: parsed.message };
}
const { action, args } = parsed;
const setUnset = parseSetUnsetCommandAction<ConfigCommand>({
slash: "/config",
action,
args,
onSet: (path, value) => ({ action: "set", path, value }),
onUnset: (path) => ({ action: "unset", path }),
onError: (message) => ({ action: "error", message }),
});
if (setUnset) {
return setUnset;
}
switch (action) {
case "show":
return { action: "show", path: args || undefined };
case "get":
return { action: "show", path: args || undefined };
case "unset":
case "set": {
const parsed = parseSetUnsetCommand({ slash: "/config", action, args });
if (parsed.kind === "error") {
return { action: "error", message: parsed.message };
}
return parsed.kind === "set"
? { action: "set", path: parsed.path, value: parsed.value }
: { action: "unset", path: parsed.path };
}
default:
return {
action: "error",