mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:51:37 +00:00
refactor(cli): share gateway service subcommands
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
export { registerDaemonCli } from "./daemon-cli/register.js";
|
export { registerDaemonCli } from "./daemon-cli/register.js";
|
||||||
|
export { addGatewayServiceCommands } from "./daemon-cli/register-service-commands.js";
|
||||||
export {
|
export {
|
||||||
runDaemonInstall,
|
runDaemonInstall,
|
||||||
runDaemonRestart,
|
runDaemonRestart,
|
||||||
|
|||||||
74
src/cli/daemon-cli/register-service-commands.ts
Normal file
74
src/cli/daemon-cli/register-service-commands.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import type { Command } from "commander";
|
||||||
|
import {
|
||||||
|
runDaemonInstall,
|
||||||
|
runDaemonRestart,
|
||||||
|
runDaemonStart,
|
||||||
|
runDaemonStatus,
|
||||||
|
runDaemonStop,
|
||||||
|
runDaemonUninstall,
|
||||||
|
} from "./runners.js";
|
||||||
|
|
||||||
|
export function addGatewayServiceCommands(parent: Command, opts?: { statusDescription?: string }) {
|
||||||
|
parent
|
||||||
|
.command("status")
|
||||||
|
.description(opts?.statusDescription ?? "Show gateway service status + probe the Gateway")
|
||||||
|
.option("--url <url>", "Gateway WebSocket URL (defaults to config/remote/local)")
|
||||||
|
.option("--token <token>", "Gateway token (if required)")
|
||||||
|
.option("--password <password>", "Gateway password (password auth)")
|
||||||
|
.option("--timeout <ms>", "Timeout in ms", "10000")
|
||||||
|
.option("--no-probe", "Skip RPC probe")
|
||||||
|
.option("--deep", "Scan system-level services", false)
|
||||||
|
.option("--json", "Output JSON", false)
|
||||||
|
.action(async (cmdOpts) => {
|
||||||
|
await runDaemonStatus({
|
||||||
|
rpc: cmdOpts,
|
||||||
|
probe: Boolean(cmdOpts.probe),
|
||||||
|
deep: Boolean(cmdOpts.deep),
|
||||||
|
json: Boolean(cmdOpts.json),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
parent
|
||||||
|
.command("install")
|
||||||
|
.description("Install the Gateway service (launchd/systemd/schtasks)")
|
||||||
|
.option("--port <port>", "Gateway port")
|
||||||
|
.option("--runtime <runtime>", "Daemon runtime (node|bun). Default: node")
|
||||||
|
.option("--token <token>", "Gateway token (token auth)")
|
||||||
|
.option("--force", "Reinstall/overwrite if already installed", false)
|
||||||
|
.option("--json", "Output JSON", false)
|
||||||
|
.action(async (cmdOpts) => {
|
||||||
|
await runDaemonInstall(cmdOpts);
|
||||||
|
});
|
||||||
|
|
||||||
|
parent
|
||||||
|
.command("uninstall")
|
||||||
|
.description("Uninstall the Gateway service (launchd/systemd/schtasks)")
|
||||||
|
.option("--json", "Output JSON", false)
|
||||||
|
.action(async (cmdOpts) => {
|
||||||
|
await runDaemonUninstall(cmdOpts);
|
||||||
|
});
|
||||||
|
|
||||||
|
parent
|
||||||
|
.command("start")
|
||||||
|
.description("Start the Gateway service (launchd/systemd/schtasks)")
|
||||||
|
.option("--json", "Output JSON", false)
|
||||||
|
.action(async (cmdOpts) => {
|
||||||
|
await runDaemonStart(cmdOpts);
|
||||||
|
});
|
||||||
|
|
||||||
|
parent
|
||||||
|
.command("stop")
|
||||||
|
.description("Stop the Gateway service (launchd/systemd/schtasks)")
|
||||||
|
.option("--json", "Output JSON", false)
|
||||||
|
.action(async (cmdOpts) => {
|
||||||
|
await runDaemonStop(cmdOpts);
|
||||||
|
});
|
||||||
|
|
||||||
|
parent
|
||||||
|
.command("restart")
|
||||||
|
.description("Restart the Gateway service (launchd/systemd/schtasks)")
|
||||||
|
.option("--json", "Output JSON", false)
|
||||||
|
.action(async (cmdOpts) => {
|
||||||
|
await runDaemonRestart(cmdOpts);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
import type { Command } from "commander";
|
import type { Command } from "commander";
|
||||||
import { formatDocsLink } from "../../terminal/links.js";
|
import { formatDocsLink } from "../../terminal/links.js";
|
||||||
import { theme } from "../../terminal/theme.js";
|
import { theme } from "../../terminal/theme.js";
|
||||||
import {
|
import { addGatewayServiceCommands } from "./register-service-commands.js";
|
||||||
runDaemonInstall,
|
|
||||||
runDaemonRestart,
|
|
||||||
runDaemonStart,
|
|
||||||
runDaemonStatus,
|
|
||||||
runDaemonStop,
|
|
||||||
runDaemonUninstall,
|
|
||||||
} from "./runners.js";
|
|
||||||
|
|
||||||
export function registerDaemonCli(program: Command) {
|
export function registerDaemonCli(program: Command) {
|
||||||
const daemon = program
|
const daemon = program
|
||||||
@@ -20,66 +13,7 @@ export function registerDaemonCli(program: Command) {
|
|||||||
`\n${theme.muted("Docs:")} ${formatDocsLink("/cli/gateway", "docs.openclaw.ai/cli/gateway")}\n`,
|
`\n${theme.muted("Docs:")} ${formatDocsLink("/cli/gateway", "docs.openclaw.ai/cli/gateway")}\n`,
|
||||||
);
|
);
|
||||||
|
|
||||||
daemon
|
addGatewayServiceCommands(daemon, {
|
||||||
.command("status")
|
statusDescription: "Show service install status + probe the Gateway",
|
||||||
.description("Show service install status + probe the Gateway")
|
});
|
||||||
.option("--url <url>", "Gateway WebSocket URL (defaults to config/remote/local)")
|
|
||||||
.option("--token <token>", "Gateway token (if required)")
|
|
||||||
.option("--password <password>", "Gateway password (password auth)")
|
|
||||||
.option("--timeout <ms>", "Timeout in ms", "10000")
|
|
||||||
.option("--no-probe", "Skip RPC probe")
|
|
||||||
.option("--deep", "Scan system-level services", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStatus({
|
|
||||||
rpc: opts,
|
|
||||||
probe: Boolean(opts.probe),
|
|
||||||
deep: Boolean(opts.deep),
|
|
||||||
json: Boolean(opts.json),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
daemon
|
|
||||||
.command("install")
|
|
||||||
.description("Install the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--port <port>", "Gateway port")
|
|
||||||
.option("--runtime <runtime>", "Daemon runtime (node|bun). Default: node")
|
|
||||||
.option("--token <token>", "Gateway token (token auth)")
|
|
||||||
.option("--force", "Reinstall/overwrite if already installed", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonInstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
daemon
|
|
||||||
.command("uninstall")
|
|
||||||
.description("Uninstall the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonUninstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
daemon
|
|
||||||
.command("start")
|
|
||||||
.description("Start the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
daemon
|
|
||||||
.command("stop")
|
|
||||||
.description("Stop the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStop(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
daemon
|
|
||||||
.command("restart")
|
|
||||||
.description("Restart the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonRestart(opts);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,7 @@ import { formatDocsLink } from "../../terminal/links.js";
|
|||||||
import { colorize, isRich, theme } from "../../terminal/theme.js";
|
import { colorize, isRich, theme } from "../../terminal/theme.js";
|
||||||
import { formatTokenCount, formatUsd } from "../../utils/usage-format.js";
|
import { formatTokenCount, formatUsd } from "../../utils/usage-format.js";
|
||||||
import { runCommandWithRuntime } from "../cli-utils.js";
|
import { runCommandWithRuntime } from "../cli-utils.js";
|
||||||
import {
|
import { addGatewayServiceCommands } from "../daemon-cli.js";
|
||||||
runDaemonInstall,
|
|
||||||
runDaemonRestart,
|
|
||||||
runDaemonStart,
|
|
||||||
runDaemonStatus,
|
|
||||||
runDaemonStop,
|
|
||||||
runDaemonUninstall,
|
|
||||||
} from "../daemon-cli.js";
|
|
||||||
import { withProgress } from "../progress.js";
|
import { withProgress } from "../progress.js";
|
||||||
import { callGatewayCli, gatewayCallOpts } from "./call.js";
|
import { callGatewayCli, gatewayCallOpts } from "./call.js";
|
||||||
import {
|
import {
|
||||||
@@ -94,68 +87,9 @@ export function registerGatewayCli(program: Command) {
|
|||||||
gateway.command("run").description("Run the WebSocket Gateway (foreground)"),
|
gateway.command("run").description("Run the WebSocket Gateway (foreground)"),
|
||||||
);
|
);
|
||||||
|
|
||||||
gateway
|
addGatewayServiceCommands(gateway, {
|
||||||
.command("status")
|
statusDescription: "Show gateway service status + probe the Gateway",
|
||||||
.description("Show gateway service status + probe the Gateway")
|
});
|
||||||
.option("--url <url>", "Gateway WebSocket URL (defaults to config/remote/local)")
|
|
||||||
.option("--token <token>", "Gateway token (if required)")
|
|
||||||
.option("--password <password>", "Gateway password (password auth)")
|
|
||||||
.option("--timeout <ms>", "Timeout in ms", "10000")
|
|
||||||
.option("--no-probe", "Skip RPC probe")
|
|
||||||
.option("--deep", "Scan system-level services", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStatus({
|
|
||||||
rpc: opts,
|
|
||||||
probe: Boolean(opts.probe),
|
|
||||||
deep: Boolean(opts.deep),
|
|
||||||
json: Boolean(opts.json),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("install")
|
|
||||||
.description("Install the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--port <port>", "Gateway port")
|
|
||||||
.option("--runtime <runtime>", "Daemon runtime (node|bun). Default: node")
|
|
||||||
.option("--token <token>", "Gateway token (token auth)")
|
|
||||||
.option("--force", "Reinstall/overwrite if already installed", false)
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonInstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("uninstall")
|
|
||||||
.description("Uninstall the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonUninstall(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("start")
|
|
||||||
.description("Start the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("stop")
|
|
||||||
.description("Stop the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonStop(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gateway
|
|
||||||
.command("restart")
|
|
||||||
.description("Restart the Gateway service (launchd/systemd/schtasks)")
|
|
||||||
.option("--json", "Output JSON", false)
|
|
||||||
.action(async (opts) => {
|
|
||||||
await runDaemonRestart(opts);
|
|
||||||
});
|
|
||||||
|
|
||||||
gatewayCallOpts(
|
gatewayCallOpts(
|
||||||
gateway
|
gateway
|
||||||
|
|||||||
Reference in New Issue
Block a user