refactor: dedupe cli lowercase helpers

This commit is contained in:
Peter Steinberger
2026-04-07 12:27:55 +01:00
parent 50265c8b1f
commit 978a0a720e
9 changed files with 33 additions and 19 deletions

View File

@@ -3,7 +3,10 @@ import type { CronJob } from "../../cron/types.js";
import { danger } from "../../globals.js";
import { sanitizeAgentId } from "../../routing/session-key.js";
import { defaultRuntime } from "../../runtime.js";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "../../shared/string-coerce.js";
import { addGatewayClientOptions, callGatewayFromCli } from "../gateway-rpc.js";
import {
applyExistingCronSchedulePatch,
@@ -279,8 +282,7 @@ export function registerCronEditCommand(cron: Command) {
failureAlert.after = after;
}
if (hasFailureAlertChannel) {
const channel = String(opts.failureAlertChannel).trim().toLowerCase();
failureAlert.channel = channel ? channel : undefined;
failureAlert.channel = normalizeOptionalLowercaseString(opts.failureAlertChannel);
}
if (hasFailureAlertTo) {
const to = String(opts.failureAlertTo).trim();
@@ -294,7 +296,7 @@ export function registerCronEditCommand(cron: Command) {
failureAlert.cooldownMs = cooldownMs;
}
if (hasFailureAlertMode) {
const mode = String(opts.failureAlertMode).trim().toLowerCase();
const mode = normalizeOptionalLowercaseString(opts.failureAlertMode);
if (mode !== "announce" && mode !== "webhook") {
throw new Error("Invalid --failure-alert-mode (must be 'announce' or 'webhook').");
}