mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-14 19:40:40 +00:00
refactor(cli): dedupe daemon install finalize
This commit is contained in:
@@ -79,3 +79,32 @@ export function createDaemonActionContext(params: { action: DaemonAction; json:
|
||||
|
||||
return { stdout, warnings, emit, fail };
|
||||
}
|
||||
|
||||
export async function installDaemonServiceAndEmit(params: {
|
||||
serviceNoun: string;
|
||||
service: GatewayService;
|
||||
warnings: string[];
|
||||
emit: (payload: Omit<DaemonActionResponse, "action">) => void;
|
||||
fail: (message: string, hints?: string[]) => void;
|
||||
install: () => Promise<void>;
|
||||
}) {
|
||||
try {
|
||||
await params.install();
|
||||
} catch (err) {
|
||||
params.fail(`${params.serviceNoun} install failed: ${String(err)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
let installed = true;
|
||||
try {
|
||||
installed = await params.service.isLoaded({ env: process.env });
|
||||
} catch {
|
||||
installed = true;
|
||||
}
|
||||
params.emit({
|
||||
ok: true,
|
||||
result: "installed",
|
||||
service: buildDaemonServiceSnapshot(params.service, installed),
|
||||
warnings: params.warnings.length ? params.warnings : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user