openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 5.39 kB
JavaScript
import{E as getCommanderErrorCommandPath,T as getCommanderErrorCommandNames,_ as getSubCliCommandMetadata,d as isRootVersionInvocation,y as getCoreCliCommandDescriptors}from"./argv-BgC5-KlV.mjs";import{t as ExitError}from"./runtime-DIcLIHcp.mjs";import"./utils-Dlk0IYAa.mjs";import{t as escapeRegExp}from"./regexp-DAJp1ywh.mjs";import{t as formatConsoleDiagnosticBlock}from"./json-console-line-C76Rgjbb.mjs";import{a as tryParseLogLevel,t as ALLOWED_LOG_LEVELS}from"./levels-i0MxdVax.mjs";import{n as resolveCommitHash}from"./git-commit-Cb3n8ZQM.mjs";import{n as isRich,r as theme}from"./theme-DS2CtI9X.mjs";import{t as formatDocsLink}from"./links-C_FK9uVv.mjs";import{t as CLI_NAME}from"./cli-name-nzTh0bJM.mjs";import{n as formatHelpExamples}from"./help-format-DLfgiheF.mjs";import{n as formatCliBannerLine,r as hasEmittedCliBanner}from"./banner-f8IJ0_7b.mjs";import{r as formatCliParseErrorOutput}from"./error-output-CzrPcvHX.mjs";import{InvalidArgumentError}from"commander";
//!src/cli/program/help.ts
const CLI_NAME_PATTERN=escapeRegExp(CLI_NAME);const CLI_LOG_LEVEL_VALUES=ALLOWED_LOG_LEVELS.join(`|`);const ROOT_COMMANDS_WITH_SUBCOMMANDS=/* @__PURE__ */ new Set([...getCoreCliCommandDescriptors().filter(e=>e.hasSubcommands).map(e=>e.name),...getSubCliCommandMetadata().filter(e=>e.hasSubcommands).map(e=>e.name)]);const ROOT_COMMANDS_HINT=`Hint: commands suffixed with * have subcommands. Run <command> --help for details.`;const EXAMPLES=[[`openclaw onboard`,`Run guided setup for a local Gateway, workspace, auth, and channels.`],[`openclaw setup --baseline`,`Create the baseline config, workspace, and session folders.`],[`openclaw configure`,`Change models, Gateway, channels, plugins, skills, and health checks.`],[`openclaw status`,`Check Gateway, channel, model, and recent-session status.`],[`openclaw doctor --fix`,`Repair common config, service, plugin, and channel problems.`],[`openclaw channels add`,`Add or update a chat channel account with guided prompts.`],[`openclaw channels status`,`See connected messaging accounts and login state.`],[`openclaw --dev gateway`,`Run a dev Gateway (isolated state/config) on ws://127.0.0.1:19001.`],[`openclaw gateway run --force`,`Start the Gateway and replace anything bound to its port.`],[`openclaw models status`,`Show model/provider auth health before running agents.`],[`openclaw plugins list`,`Inspect enabled, disabled, and installed plugins.`],[`openclaw agent --to +15555550123 --message "Run summary" --deliver`,`Run one agent turn through the Gateway and optionally deliver the reply.`],[`openclaw message send --channel telegram --target @mychat --message "Hi"`,`Send via your Telegram bot.`]];function formatProgramHelpOutput(e){let t=e;if(new RegExp(`^Usage:\\s+${CLI_NAME_PATTERN}\\s+\\[options\\]\\s+\\[command\\]\\s*$`,`m`).test(t)&&/^Commands:/m.test(t))t=t.replace(/^Commands:/m,`Commands:\n ${theme.muted(ROOT_COMMANDS_HINT)}`);return t.replace(/^Usage:/gm,theme.heading(`Usage:`)).replace(/^Options:/gm,theme.heading(`Options:`)).replace(/^Commands:/gm,theme.heading(`Commands:`))}function configureProgramHelp(e,t,n){const r=/* @__PURE__ */ new Set([...ROOT_COMMANDS_WITH_SUBCOMMANDS,...n?.commandsWithSubcommands??[]]);e.name(CLI_NAME).description(``).version(t.programVersion).option(`--container <name>`,`Run the CLI inside a running Podman/Docker container named <name> (default: env OPENCLAW_CONTAINER)`).option(`--dev`,`Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)`).option(`--profile <name>`,`Use a named profile (isolates OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATH under ~/.openclaw-<name>)`).option(`--log-level <level>`,`Global log level override for file + console (${CLI_LOG_LEVEL_VALUES})`,e=>{const t=tryParseLogLevel(e);if(!t)throw new InvalidArgumentError(`Invalid --log-level (use ${CLI_LOG_LEVEL_VALUES})`);return t});e.option(`--no-color`,`Disable ANSI colors`,false);e.helpOption(`-h, --help`,`Display help for command`);e.helpCommand(`help [command]`,`Display help for command`);e.configureHelp({sortSubcommands:true,sortOptions:true,optionTerm:e=>theme.option(e.flags),subcommandTerm:t=>{const n=t.parent===e&&r.has(t.name());return theme.command(n?`${t.name()} *`:t.name())}});e.configureOutput({writeOut:e=>{process.stdout.write(formatProgramHelpOutput(e))},writeErr:e=>{const t=formatProgramHelpOutput(e);process.stderr.write(formatConsoleDiagnosticBlock({message:t}))},outputError:(t,n)=>{n(formatCliParseErrorOutput(t,{argv:process.argv,commandPath:getCommanderErrorCommandPath(e),commandNames:getCommanderErrorCommandNames(e)}))}});if(isRootVersionInvocation(process.argv)){const e=resolveCommitHash({moduleUrl:import.meta.url});console.log(e?`OpenClaw ${t.programVersion} (${e})`:`OpenClaw ${t.programVersion}`);throw new ExitError(0)}e.addHelpText(`beforeAll`,()=>{if(hasEmittedCliBanner()||process.env.OPENCLAW_SUPPRESS_HELP_BANNER===`1`)return``;const e=isRich();return`\n${formatCliBannerLine(t.programVersion,{richTty:e,mode:`default`})}\n`});const i=formatHelpExamples(EXAMPLES);e.addHelpText(`afterAll`,({command:t})=>{if(t!==e)return``;const n=formatDocsLink(`/cli`,`docs.openclaw.ai/cli`);return`\n${theme.heading(`Examples:`)}\n${i}\n\n${theme.muted(`Docs:`)} ${n}\n${theme.muted(`Support:`)} https://community.openclaw.ai/\n`})}export{formatProgramHelpOutput as n,configureProgramHelp as t};