mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
refactor(cli): share daemon action reporting
This commit is contained in:
@@ -22,11 +22,7 @@ import {
|
||||
runServiceStop,
|
||||
runServiceUninstall,
|
||||
} from "../daemon-cli/lifecycle-core.js";
|
||||
import {
|
||||
buildDaemonServiceSnapshot,
|
||||
createNullWriter,
|
||||
emitDaemonActionJson,
|
||||
} from "../daemon-cli/response.js";
|
||||
import { buildDaemonServiceSnapshot, createDaemonActionContext } from "../daemon-cli/response.js";
|
||||
import { formatRuntimeStatus, parsePort } from "../daemon-cli/shared.js";
|
||||
|
||||
type NodeDaemonInstallOptions = {
|
||||
@@ -100,45 +96,7 @@ function resolveNodeDefaults(
|
||||
|
||||
export async function runNodeDaemonInstall(opts: NodeDaemonInstallOptions) {
|
||||
const json = Boolean(opts.json);
|
||||
const warnings: string[] = [];
|
||||
const stdout = json ? createNullWriter() : process.stdout;
|
||||
const emit = (payload: {
|
||||
ok: boolean;
|
||||
result?: string;
|
||||
message?: string;
|
||||
error?: string;
|
||||
service?: {
|
||||
label: string;
|
||||
loaded: boolean;
|
||||
loadedText: string;
|
||||
notLoadedText: string;
|
||||
};
|
||||
hints?: string[];
|
||||
warnings?: string[];
|
||||
}) => {
|
||||
if (!json) {
|
||||
return;
|
||||
}
|
||||
emitDaemonActionJson({ action: "install", ...payload });
|
||||
};
|
||||
const fail = (message: string, hints?: string[]) => {
|
||||
if (json) {
|
||||
emit({
|
||||
ok: false,
|
||||
error: message,
|
||||
hints,
|
||||
warnings: warnings.length ? warnings : undefined,
|
||||
});
|
||||
} else {
|
||||
defaultRuntime.error(message);
|
||||
if (hints?.length) {
|
||||
for (const hint of hints) {
|
||||
defaultRuntime.log(`Tip: ${hint}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
defaultRuntime.exit(1);
|
||||
};
|
||||
const { stdout, warnings, emit, fail } = createDaemonActionContext({ action: "install", json });
|
||||
|
||||
if (resolveIsNixMode(process.env)) {
|
||||
fail("Nix mode detected; service install is disabled.");
|
||||
|
||||
Reference in New Issue
Block a user