forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp-format.ts
More file actions
27 lines (22 loc) · 978 Bytes
/
help-format.ts
File metadata and controls
27 lines (22 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { theme } from "../terminal/theme.js";
export type HelpExample = readonly [command: string, description: string];
export function formatHelpExample(command: string, description: string): string {
return ` ${theme.command(command)}\n ${theme.muted(description)}`;
}
export function formatHelpExampleLine(command: string, description: string): string {
if (!description) {
return ` ${theme.command(command)}`;
}
return ` ${theme.command(command)} ${theme.muted(`# ${description}`)}`;
}
export function formatHelpExamples(examples: ReadonlyArray<HelpExample>, inline = false): string {
const formatter = inline ? formatHelpExampleLine : formatHelpExample;
return examples.map(([command, description]) => formatter(command, description)).join("\n");
}
export function formatHelpExampleGroup(
label: string,
examples: ReadonlyArray<HelpExample>,
inline = false,
) {
return `${theme.muted(label)}\n${formatHelpExamples(examples, inline)}`;
}