diff --git a/src/cli/daemon-cli.ts b/src/cli/daemon-cli.ts index 4260e119e..ff2f3970e 100644 --- a/src/cli/daemon-cli.ts +++ b/src/cli/daemon-cli.ts @@ -1,4 +1,5 @@ export { registerDaemonCli } from "./daemon-cli/register.js"; +export { addGatewayServiceCommands } from "./daemon-cli/register-service-commands.js"; export { runDaemonInstall, runDaemonRestart, diff --git a/src/cli/daemon-cli/register-service-commands.ts b/src/cli/daemon-cli/register-service-commands.ts new file mode 100644 index 000000000..1cfe3881e --- /dev/null +++ b/src/cli/daemon-cli/register-service-commands.ts @@ -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 ", "Gateway WebSocket URL (defaults to config/remote/local)") + .option("--token ", "Gateway token (if required)") + .option("--password ", "Gateway password (password auth)") + .option("--timeout ", "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 ", "Gateway port") + .option("--runtime ", "Daemon runtime (node|bun). Default: node") + .option("--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); + }); +} diff --git a/src/cli/daemon-cli/register.ts b/src/cli/daemon-cli/register.ts index 47e3dd09b..6c2595eb4 100644 --- a/src/cli/daemon-cli/register.ts +++ b/src/cli/daemon-cli/register.ts @@ -1,14 +1,7 @@ import type { Command } from "commander"; import { formatDocsLink } from "../../terminal/links.js"; import { theme } from "../../terminal/theme.js"; -import { - runDaemonInstall, - runDaemonRestart, - runDaemonStart, - runDaemonStatus, - runDaemonStop, - runDaemonUninstall, -} from "./runners.js"; +import { addGatewayServiceCommands } from "./register-service-commands.js"; export function registerDaemonCli(program: Command) { 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`, ); - daemon - .command("status") - .description("Show service install status + probe the Gateway") - .option("--url ", "Gateway WebSocket URL (defaults to config/remote/local)") - .option("--token ", "Gateway token (if required)") - .option("--password ", "Gateway password (password auth)") - .option("--timeout ", "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 ", "Gateway port") - .option("--runtime ", "Daemon runtime (node|bun). Default: node") - .option("--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); - }); + addGatewayServiceCommands(daemon, { + statusDescription: "Show service install status + probe the Gateway", + }); } diff --git a/src/cli/gateway-cli/register.ts b/src/cli/gateway-cli/register.ts index ea5ac4684..40c46053c 100644 --- a/src/cli/gateway-cli/register.ts +++ b/src/cli/gateway-cli/register.ts @@ -12,14 +12,7 @@ import { formatDocsLink } from "../../terminal/links.js"; import { colorize, isRich, theme } from "../../terminal/theme.js"; import { formatTokenCount, formatUsd } from "../../utils/usage-format.js"; import { runCommandWithRuntime } from "../cli-utils.js"; -import { - runDaemonInstall, - runDaemonRestart, - runDaemonStart, - runDaemonStatus, - runDaemonStop, - runDaemonUninstall, -} from "../daemon-cli.js"; +import { addGatewayServiceCommands } from "../daemon-cli.js"; import { withProgress } from "../progress.js"; import { callGatewayCli, gatewayCallOpts } from "./call.js"; import { @@ -94,68 +87,9 @@ export function registerGatewayCli(program: Command) { gateway.command("run").description("Run the WebSocket Gateway (foreground)"), ); - gateway - .command("status") - .description("Show gateway service status + probe the Gateway") - .option("--url ", "Gateway WebSocket URL (defaults to config/remote/local)") - .option("--token ", "Gateway token (if required)") - .option("--password ", "Gateway password (password auth)") - .option("--timeout ", "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 ", "Gateway port") - .option("--runtime ", "Daemon runtime (node|bun). Default: node") - .option("--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); - }); + addGatewayServiceCommands(gateway, { + statusDescription: "Show gateway service status + probe the Gateway", + }); gatewayCallOpts( gateway