mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:31:24 +00:00
refactor(daemon): share quoted arg splitter
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
import { splitArgsPreservingQuotes } from "./arg-split.js";
|
||||
import { formatGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
||||
import { formatLine } from "./output.js";
|
||||
import { resolveGatewayStateDir } from "./paths.js";
|
||||
@@ -48,36 +49,9 @@ function resolveTaskUser(env: Record<string, string | undefined>): string | null
|
||||
}
|
||||
|
||||
function parseCommandLine(value: string): string[] {
|
||||
const args: string[] = [];
|
||||
let current = "";
|
||||
let inQuotes = false;
|
||||
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const char = value[i];
|
||||
// `buildTaskScript` only escapes quotes (`\"`).
|
||||
// Keep all other backslashes literal so drive and UNC paths are preserved.
|
||||
if (char === "\\" && i + 1 < value.length && value[i + 1] === '"') {
|
||||
current += value[i + 1];
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (char === '"') {
|
||||
inQuotes = !inQuotes;
|
||||
continue;
|
||||
}
|
||||
if (!inQuotes && /\s/.test(char)) {
|
||||
if (current) {
|
||||
args.push(current);
|
||||
current = "";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
current += char;
|
||||
}
|
||||
if (current) {
|
||||
args.push(current);
|
||||
}
|
||||
return args;
|
||||
// `buildTaskScript` only escapes quotes (`\"`).
|
||||
// Keep all other backslashes literal so drive and UNC paths are preserved.
|
||||
return splitArgsPreservingQuotes(value, { escapeMode: "backslash-quote-only" });
|
||||
}
|
||||
|
||||
export async function readScheduledTaskCommand(env: Record<string, string | undefined>): Promise<{
|
||||
|
||||
Reference in New Issue
Block a user