(program: Command, ctx: ProgramContext)
| 45 | ] as const; |
| 46 | |
| 47 | export function configureProgramHelp(program: Command, ctx: ProgramContext) { |
| 48 | program |
| 49 | .name(CLI_NAME) |
| 50 | .description("") |
| 51 | .version(ctx.programVersion) |
| 52 | .option( |
| 53 | "--dev", |
| 54 | "Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)", |
| 55 | ) |
| 56 | .option( |
| 57 | "--profile <name>", |
| 58 | "Use a named profile (isolates OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATH under ~/.openclaw-<name>)", |
| 59 | ) |
| 60 | .option( |
| 61 | "--log-level <level>", |
| 62 | `Global log level override for file + console (${CLI_LOG_LEVEL_VALUES})`, |
| 63 | parseCliLogLevelOption, |
| 64 | ); |
| 65 | |
| 66 | program.option("--no-color", "Disable ANSI colors", false); |
| 67 | program.helpOption("-h, --help", "Display help for command"); |
| 68 | program.helpCommand("help [command]", "Display help for command"); |
| 69 | |
| 70 | program.configureHelp({ |
| 71 | // sort options and subcommands alphabetically |
| 72 | sortSubcommands: true, |
| 73 | sortOptions: true, |
| 74 | optionTerm: (option) => theme.option(option.flags), |
| 75 | subcommandTerm: (cmd) => { |
| 76 | const isRootCommand = cmd.parent === program; |
| 77 | const hasSubcommands = isRootCommand && ROOT_COMMANDS_WITH_SUBCOMMANDS.has(cmd.name()); |
| 78 | return theme.command(hasSubcommands ? `${cmd.name()} *` : cmd.name()); |
| 79 | }, |
| 80 | }); |
| 81 | |
| 82 | const formatHelpOutput = (str: string) => { |
| 83 | let output = str; |
| 84 | const isRootHelp = new RegExp( |
| 85 | `^Usage:\\s+${CLI_NAME_PATTERN}\\s+\\[options\\]\\s+\\[command\\]\\s*$`, |
| 86 | "m", |
| 87 | ).test(output); |
| 88 | if (isRootHelp && /^Commands:/m.test(output)) { |
| 89 | output = output.replace(/^Commands:/m, `Commands:\n ${theme.muted(ROOT_COMMANDS_HINT)}`); |
| 90 | } |
| 91 | |
| 92 | return output |
| 93 | .replace(/^Usage:/gm, theme.heading("Usage:")) |
| 94 | .replace(/^Options:/gm, theme.heading("Options:")) |
| 95 | .replace(/^Commands:/gm, theme.heading("Commands:")); |
| 96 | }; |
| 97 | |
| 98 | program.configureOutput({ |
| 99 | writeOut: (str) => { |
| 100 | process.stdout.write(formatHelpOutput(str)); |
| 101 | }, |
| 102 | writeErr: (str) => { |
| 103 | process.stderr.write(formatHelpOutput(str)); |
| 104 | }, |
no test coverage detected