Files
openclaw/src/cli/program/preaction.ts

28 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-01-14 01:08:15 +00:00
import type { Command } from "commander";
import { defaultRuntime } from "../../runtime.js";
2026-01-14 01:08:15 +00:00
import { emitCliBanner } from "../banner.js";
2026-01-19 03:38:51 +00:00
import { getCommandPath, hasHelpOrVersion } from "../argv.js";
import { ensureConfigReady } from "./config-guard.js";
2026-01-14 01:08:15 +00:00
2026-01-16 01:33:20 +00:00
function setProcessTitleForCommand(actionCommand: Command) {
let current: Command = actionCommand;
while (current.parent && current.parent.parent) {
current = current.parent;
}
const name = current.name();
if (!name || name === "clawdbot") return;
process.title = `clawdbot-${name}`;
}
export function registerPreActionHooks(program: Command, programVersion: string) {
2026-01-14 01:08:15 +00:00
program.hook("preAction", async (_thisCommand, actionCommand) => {
2026-01-16 01:33:20 +00:00
setProcessTitleForCommand(actionCommand);
2026-01-14 01:08:15 +00:00
emitCliBanner(programVersion);
const argv = process.argv;
if (hasHelpOrVersion(argv)) return;
2026-01-19 03:38:51 +00:00
const commandPath = getCommandPath(argv, 2);
if (commandPath[0] === "doctor") return;
await ensureConfigReady({ runtime: defaultRuntime, commandPath });
2026-01-14 01:08:15 +00:00
});
}