feat(cli): colorize gateway health + daemon output
This commit is contained in:
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
||||
import {
|
||||
GATEWAY_LAUNCH_AGENT_LABEL,
|
||||
LEGACY_GATEWAY_LAUNCH_AGENT_LABELS,
|
||||
@@ -11,6 +12,11 @@ import { parseKeyValueOutput } from "./runtime-parse.js";
|
||||
import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
const formatLine = (label: string, value: string) => {
|
||||
const rich = isRich();
|
||||
return `${colorize(rich, theme.muted, `${label}:`)} ${colorize(rich, theme.command, value)}`;
|
||||
};
|
||||
function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
const home = env.HOME?.trim() || env.USERPROFILE?.trim();
|
||||
if (!home) throw new Error("Missing HOME");
|
||||
@@ -378,7 +384,9 @@ export async function uninstallLegacyLaunchAgents({
|
||||
const dest = path.join(trashDir, `${agent.label}.plist`);
|
||||
try {
|
||||
await fs.rename(agent.plistPath, dest);
|
||||
stdout.write(`Moved legacy LaunchAgent to Trash: ${dest}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Moved legacy LaunchAgent to Trash", dest)}\n`,
|
||||
);
|
||||
} catch {
|
||||
stdout.write(
|
||||
`Legacy LaunchAgent remains at ${agent.plistPath} (could not move)\n`,
|
||||
@@ -414,7 +422,7 @@ export async function uninstallLaunchAgent({
|
||||
try {
|
||||
await fs.mkdir(trashDir, { recursive: true });
|
||||
await fs.rename(plistPath, dest);
|
||||
stdout.write(`Moved LaunchAgent to Trash: ${dest}\n`);
|
||||
stdout.write(`${formatLine("Moved LaunchAgent to Trash", dest)}\n`);
|
||||
} catch {
|
||||
stdout.write(`LaunchAgent remains at ${plistPath} (could not move)\n`);
|
||||
}
|
||||
@@ -446,7 +454,7 @@ export async function stopLaunchAgent({
|
||||
`launchctl bootout failed: ${res.stderr || res.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
stdout.write(`Stopped LaunchAgent: ${domain}/${label}\n`);
|
||||
stdout.write(`${formatLine("Stopped LaunchAgent", `${domain}/${label}`)}\n`);
|
||||
}
|
||||
|
||||
export async function installLaunchAgent({
|
||||
@@ -507,8 +515,8 @@ export async function installLaunchAgent({
|
||||
`${domain}/${GATEWAY_LAUNCH_AGENT_LABEL}`,
|
||||
]);
|
||||
|
||||
stdout.write(`Installed LaunchAgent: ${plistPath}\n`);
|
||||
stdout.write(`Logs: ${stdoutPath}\n`);
|
||||
stdout.write(`${formatLine("Installed LaunchAgent", plistPath)}\n`);
|
||||
stdout.write(`${formatLine("Logs", stdoutPath)}\n`);
|
||||
return { plistPath };
|
||||
}
|
||||
|
||||
@@ -525,5 +533,7 @@ export async function restartLaunchAgent({
|
||||
`launchctl kickstart failed: ${res.stderr || res.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
stdout.write(`Restarted LaunchAgent: ${domain}/${label}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Restarted LaunchAgent", `${domain}/${label}`)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
||||
import {
|
||||
GATEWAY_WINDOWS_TASK_NAME,
|
||||
LEGACY_GATEWAY_WINDOWS_TASK_NAMES,
|
||||
@@ -12,6 +13,11 @@ import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
const formatLine = (label: string, value: string) => {
|
||||
const rich = isRich();
|
||||
return `${colorize(rich, theme.muted, `${label}:`)} ${colorize(rich, theme.command, value)}`;
|
||||
};
|
||||
|
||||
function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
const home = env.USERPROFILE?.trim() || env.HOME?.trim();
|
||||
if (!home) throw new Error("Missing HOME");
|
||||
@@ -229,8 +235,10 @@ export async function installScheduledTask({
|
||||
}
|
||||
|
||||
await execSchtasks(["/Run", "/TN", GATEWAY_WINDOWS_TASK_NAME]);
|
||||
stdout.write(`Installed Scheduled Task: ${GATEWAY_WINDOWS_TASK_NAME}\n`);
|
||||
stdout.write(`Task script: ${scriptPath}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Installed Scheduled Task", GATEWAY_WINDOWS_TASK_NAME)}\n`,
|
||||
);
|
||||
stdout.write(`${formatLine("Task script", scriptPath)}\n`);
|
||||
return { scriptPath };
|
||||
}
|
||||
|
||||
@@ -247,7 +255,7 @@ export async function uninstallScheduledTask({
|
||||
const scriptPath = resolveTaskScriptPath(env);
|
||||
try {
|
||||
await fs.unlink(scriptPath);
|
||||
stdout.write(`Removed task script: ${scriptPath}\n`);
|
||||
stdout.write(`${formatLine("Removed task script", scriptPath)}\n`);
|
||||
} catch {
|
||||
stdout.write(`Task script not found at ${scriptPath}\n`);
|
||||
}
|
||||
@@ -272,7 +280,9 @@ export async function stopScheduledTask({
|
||||
if (res.code !== 0 && !isTaskNotRunning(res)) {
|
||||
throw new Error(`schtasks end failed: ${res.stderr || res.stdout}`.trim());
|
||||
}
|
||||
stdout.write(`Stopped Scheduled Task: ${GATEWAY_WINDOWS_TASK_NAME}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Stopped Scheduled Task", GATEWAY_WINDOWS_TASK_NAME)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function restartScheduledTask({
|
||||
@@ -286,7 +296,9 @@ export async function restartScheduledTask({
|
||||
if (res.code !== 0) {
|
||||
throw new Error(`schtasks run failed: ${res.stderr || res.stdout}`.trim());
|
||||
}
|
||||
stdout.write(`Restarted Scheduled Task: ${GATEWAY_WINDOWS_TASK_NAME}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Restarted Scheduled Task", GATEWAY_WINDOWS_TASK_NAME)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function isScheduledTaskInstalled(): Promise<boolean> {
|
||||
@@ -400,7 +412,9 @@ export async function uninstallLegacyScheduledTasks({
|
||||
|
||||
try {
|
||||
await fs.unlink(task.scriptPath);
|
||||
stdout.write(`Removed legacy task script: ${task.scriptPath}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Removed legacy task script", task.scriptPath)}\n`,
|
||||
);
|
||||
} catch {
|
||||
stdout.write(`Legacy task script not found at ${task.scriptPath}\n`);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { runCommandWithTimeout, runExec } from "../process/exec.js";
|
||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
||||
import {
|
||||
GATEWAY_SYSTEMD_SERVICE_NAME,
|
||||
LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES,
|
||||
@@ -13,6 +14,11 @@ import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
const formatLine = (label: string, value: string) => {
|
||||
const rich = isRich();
|
||||
return `${colorize(rich, theme.muted, `${label}:`)} ${colorize(rich, theme.command, value)}`;
|
||||
};
|
||||
|
||||
function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
const home = env.HOME?.trim() || env.USERPROFILE?.trim();
|
||||
if (!home) throw new Error("Missing HOME");
|
||||
@@ -410,7 +416,7 @@ export async function installSystemdService({
|
||||
);
|
||||
}
|
||||
|
||||
stdout.write(`Installed systemd service: ${unitPath}\n`);
|
||||
stdout.write(`${formatLine("Installed systemd service", unitPath)}\n`);
|
||||
return { unitPath };
|
||||
}
|
||||
|
||||
@@ -428,7 +434,7 @@ export async function uninstallSystemdService({
|
||||
const unitPath = resolveSystemdUnitPath(env);
|
||||
try {
|
||||
await fs.unlink(unitPath);
|
||||
stdout.write(`Removed systemd service: ${unitPath}\n`);
|
||||
stdout.write(`${formatLine("Removed systemd service", unitPath)}\n`);
|
||||
} catch {
|
||||
stdout.write(`Systemd service not found at ${unitPath}\n`);
|
||||
}
|
||||
@@ -447,7 +453,7 @@ export async function stopSystemdService({
|
||||
`systemctl stop failed: ${res.stderr || res.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
stdout.write(`Stopped systemd service: ${unitName}\n`);
|
||||
stdout.write(`${formatLine("Stopped systemd service", unitName)}\n`);
|
||||
}
|
||||
|
||||
export async function restartSystemdService({
|
||||
@@ -463,7 +469,7 @@ export async function restartSystemdService({
|
||||
`systemctl restart failed: ${res.stderr || res.stdout}`.trim(),
|
||||
);
|
||||
}
|
||||
stdout.write(`Restarted systemd service: ${unitName}\n`);
|
||||
stdout.write(`${formatLine("Restarted systemd service", unitName)}\n`);
|
||||
}
|
||||
|
||||
export async function isSystemdServiceEnabled(): Promise<boolean> {
|
||||
@@ -584,7 +590,9 @@ export async function uninstallLegacySystemdUnits({
|
||||
|
||||
try {
|
||||
await fs.unlink(unit.unitPath);
|
||||
stdout.write(`Removed legacy systemd service: ${unit.unitPath}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Removed legacy systemd service", unit.unitPath)}\n`,
|
||||
);
|
||||
} catch {
|
||||
stdout.write(`Legacy systemd unit not found at ${unit.unitPath}\n`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user