MCPcopy Create free account
hub / github.com/beita6969/ScienceClaw / configureProgramHelp

Function configureProgramHelp

src/cli/program/help.ts:47–140  ·  view source on GitHub ↗
(program: Command, ctx: ProgramContext)

Source from the content-addressed store, hash-verified

45] as const;
46
47export 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 },

Callers 2

help.test.tsFile · 0.85
buildProgramFunction · 0.85

Calls 14

formatHelpOutputFunction · 0.85
hasRootVersionAliasFunction · 0.85
resolveCommitHashFunction · 0.85
hasEmittedCliBannerFunction · 0.85
formatCliBannerLineFunction · 0.85
replaceCliNameFunction · 0.85
formatDocsLinkFunction · 0.85
commandMethod · 0.80
joinMethod · 0.80
errorMethod · 0.65
writeFunction · 0.50
hasFlagFunction · 0.50

Tested by

no test coverage detected