mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:41:23 +00:00
refactor(daemon): dedupe install output line writing
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
|||||||
buildLaunchAgentPlist as buildLaunchAgentPlistImpl,
|
buildLaunchAgentPlist as buildLaunchAgentPlistImpl,
|
||||||
readLaunchAgentProgramArgumentsFromFile,
|
readLaunchAgentProgramArgumentsFromFile,
|
||||||
} from "./launchd-plist.js";
|
} from "./launchd-plist.js";
|
||||||
import { formatLine, toPosixPath } from "./output.js";
|
import { formatLine, toPosixPath, writeFormattedLines } from "./output.js";
|
||||||
import { resolveGatewayStateDir, resolveHomeDir } from "./paths.js";
|
import { resolveGatewayStateDir, resolveHomeDir } from "./paths.js";
|
||||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||||
@@ -407,9 +407,14 @@ export async function installLaunchAgent({
|
|||||||
await execLaunchctl(["kickstart", "-k", `${domain}/${label}`]);
|
await execLaunchctl(["kickstart", "-k", `${domain}/${label}`]);
|
||||||
|
|
||||||
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
||||||
stdout.write("\n");
|
writeFormattedLines(
|
||||||
stdout.write(`${formatLine("Installed LaunchAgent", plistPath)}\n`);
|
stdout,
|
||||||
stdout.write(`${formatLine("Logs", stdoutPath)}\n`);
|
[
|
||||||
|
{ label: "Installed LaunchAgent", value: plistPath },
|
||||||
|
{ label: "Logs", value: stdoutPath },
|
||||||
|
],
|
||||||
|
{ leadingBlankLine: true },
|
||||||
|
);
|
||||||
return { plistPath };
|
return { plistPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,16 @@ export function formatLine(label: string, value: string): string {
|
|||||||
const rich = isRich();
|
const rich = isRich();
|
||||||
return `${colorize(rich, theme.muted, `${label}:`)} ${colorize(rich, theme.command, value)}`;
|
return `${colorize(rich, theme.muted, `${label}:`)} ${colorize(rich, theme.command, value)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function writeFormattedLines(
|
||||||
|
stdout: NodeJS.WritableStream,
|
||||||
|
lines: Array<{ label: string; value: string }>,
|
||||||
|
opts?: { leadingBlankLine?: boolean },
|
||||||
|
): void {
|
||||||
|
if (opts?.leadingBlankLine) {
|
||||||
|
stdout.write("\n");
|
||||||
|
}
|
||||||
|
for (const line of lines) {
|
||||||
|
stdout.write(`${formatLine(line.label, line.value)}\n`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { splitArgsPreservingQuotes } from "./arg-split.js";
|
import { splitArgsPreservingQuotes } from "./arg-split.js";
|
||||||
import { resolveGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
import { resolveGatewayServiceDescription, resolveGatewayWindowsTaskName } from "./constants.js";
|
||||||
import { formatLine } from "./output.js";
|
import { formatLine, writeFormattedLines } from "./output.js";
|
||||||
import { resolveGatewayStateDir } from "./paths.js";
|
import { resolveGatewayStateDir } from "./paths.js";
|
||||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||||
import { execSchtasks } from "./schtasks-exec.js";
|
import { execSchtasks } from "./schtasks-exec.js";
|
||||||
@@ -230,9 +230,14 @@ export async function installScheduledTask({
|
|||||||
|
|
||||||
await execSchtasks(["/Run", "/TN", taskName]);
|
await execSchtasks(["/Run", "/TN", taskName]);
|
||||||
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
||||||
stdout.write("\n");
|
writeFormattedLines(
|
||||||
stdout.write(`${formatLine("Installed Scheduled Task", taskName)}\n`);
|
stdout,
|
||||||
stdout.write(`${formatLine("Task script", scriptPath)}\n`);
|
[
|
||||||
|
{ label: "Installed Scheduled Task", value: taskName },
|
||||||
|
{ label: "Task script", value: scriptPath },
|
||||||
|
],
|
||||||
|
{ leadingBlankLine: true },
|
||||||
|
);
|
||||||
return { scriptPath };
|
return { scriptPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
resolveGatewaySystemdServiceName,
|
resolveGatewaySystemdServiceName,
|
||||||
} from "./constants.js";
|
} from "./constants.js";
|
||||||
import { execFileUtf8 } from "./exec-file.js";
|
import { execFileUtf8 } from "./exec-file.js";
|
||||||
import { formatLine, toPosixPath } from "./output.js";
|
import { formatLine, toPosixPath, writeFormattedLines } from "./output.js";
|
||||||
import { resolveHomeDir } from "./paths.js";
|
import { resolveHomeDir } from "./paths.js";
|
||||||
import { parseKeyValueOutput } from "./runtime-parse.js";
|
import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||||
@@ -227,8 +227,16 @@ export async function installSystemdService({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
// Ensure we don't end up writing to a clack spinner line (wizards show progress without a newline).
|
||||||
stdout.write("\n");
|
writeFormattedLines(
|
||||||
stdout.write(`${formatLine("Installed systemd service", unitPath)}\n`);
|
stdout,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: "Installed systemd service",
|
||||||
|
value: unitPath,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ leadingBlankLine: true },
|
||||||
|
);
|
||||||
return { unitPath };
|
return { unitPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user