Files
cronmaster/app/_utils/wrapper-utils-client.ts
2026-05-12 14:00:29 +01:00

42 lines
1.0 KiB
TypeScript

const SH_C_PREFIX = /^sh -c '/;
export const toShellArg = (cmd: string): string =>
SH_C_PREFIX.test(cmd) ? cmd : `sh -c '${cmd.replace(/'/g, "'\\''")}'`;
export const fromShellArg = (cmd: string): string => {
const match = cmd.match(/^sh -c '(.*)'$/);
if (!match) return cmd;
return match[1].replace(/'\\''/g, "'");
};
export const unwrapCommand = (command: string): string => {
const wrapperPattern = /^(.+\/cron-log-wrapper\.sh)\s+"([^"]+)"\s+(.+)$/;
const match = command.match(wrapperPattern);
if (match && match[3]) {
return fromShellArg(match[3]);
}
return command;
};
export const isCommandWrapped = (command: string): boolean => {
const wrapperPattern = /\/cron-log-wrapper\.sh\s+"[^"]+"\s+/;
return wrapperPattern.test(command);
};
export const extractJobIdFromWrappedCommand = (
command: string
): string | null => {
const wrapperPattern = /\/cron-log-wrapper\.sh\s+"([^"]+)"\s+/;
const match = command.match(wrapperPattern);
if (match && match[1]) {
return match[1];
}
return null;
};