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

89 lines
3.1 KiB
TypeScript
Raw Normal View History

2026-01-14 01:08:15 +00:00
import type { Command } from "commander";
import { formatDocsLink } from "../../terminal/links.js";
import { isRich, theme } from "../../terminal/theme.js";
import { formatCliBannerLine, hasEmittedCliBanner } from "../banner.js";
2026-01-27 11:27:41 +00:00
import { replaceCliName, resolveCliName } from "../cli-name.js";
2026-01-14 01:08:15 +00:00
import type { ProgramContext } from "./context.js";
2026-01-27 11:27:41 +00:00
const CLI_NAME = resolveCliName();
2026-01-14 01:08:15 +00:00
const EXAMPLES = [
["moltbot channels login --verbose", "Link personal WhatsApp Web and show QR + connection logs."],
2026-01-14 01:08:15 +00:00
[
'moltbot message send --target +15555550123 --message "Hi" --json',
2026-01-14 01:08:15 +00:00
"Send via your web session and print JSON result.",
],
["moltbot gateway --port 18789", "Run the WebSocket Gateway locally."],
["moltbot --dev gateway", "Run a dev Gateway (isolated state/config) on ws://127.0.0.1:19001."],
["moltbot gateway --force", "Kill anything bound to the default gateway port, then start it."],
["moltbot gateway ...", "Gateway control via WebSocket."],
2026-01-14 01:08:15 +00:00
[
'moltbot agent --to +15555550123 --message "Run summary" --deliver',
2026-01-14 01:08:15 +00:00
"Talk directly to the agent using the Gateway; optionally send the WhatsApp reply.",
],
[
'moltbot message send --channel telegram --target @mychat --message "Hi"',
2026-01-14 01:08:15 +00:00
"Send via your Telegram bot.",
],
] as const;
export function configureProgramHelp(program: Command, ctx: ProgramContext) {
program
2026-01-27 11:27:41 +00:00
.name(CLI_NAME)
2026-01-14 01:08:15 +00:00
.description("")
.version(ctx.programVersion)
.option(
"--dev",
2026-01-19 04:50:07 +00:00
"Dev profile: isolate state under ~/.clawdbot-dev, default gateway port 19001, and shift derived ports (browser/canvas)",
2026-01-14 01:08:15 +00:00
)
.option(
"--profile <name>",
"Use a named profile (isolates CLAWDBOT_STATE_DIR/CLAWDBOT_CONFIG_PATH under ~/.clawdbot-<name>)",
);
program.option("--no-color", "Disable ANSI colors", false);
program.configureHelp({
optionTerm: (option) => theme.option(option.flags),
subcommandTerm: (cmd) => theme.command(cmd.name()),
});
program.configureOutput({
writeOut: (str) => {
const colored = str
.replace(/^Usage:/gm, theme.heading("Usage:"))
.replace(/^Options:/gm, theme.heading("Options:"))
.replace(/^Commands:/gm, theme.heading("Commands:"));
process.stdout.write(colored);
},
writeErr: (str) => process.stderr.write(str),
outputError: (str, write) => write(theme.error(str)),
});
if (
process.argv.includes("-V") ||
process.argv.includes("--version") ||
process.argv.includes("-v")
) {
console.log(ctx.programVersion);
process.exit(0);
}
program.addHelpText("beforeAll", () => {
if (hasEmittedCliBanner()) return "";
const rich = isRich();
const line = formatCliBannerLine(ctx.programVersion, { richTty: rich });
return `\n${line}\n`;
});
const fmtExamples = EXAMPLES.map(
2026-01-27 11:27:41 +00:00
([cmd, desc]) => ` ${theme.command(replaceCliName(cmd, CLI_NAME))}\n ${theme.muted(desc)}`,
2026-01-14 01:08:15 +00:00
).join("\n");
program.addHelpText("afterAll", ({ command }) => {
if (command !== program) return "";
2026-01-27 11:27:41 +00:00
const docs = formatDocsLink("/cli", "docs.molt.bot/cli");
return `\n${theme.heading("Examples:")}\n${fmtExamples}\n\n${theme.muted("Docs:")} ${docs}\n`;
2026-01-14 01:08:15 +00:00
});
}