fix: align cli output tests and help examples

This commit is contained in:
Peter Steinberger
2026-01-21 05:20:31 +00:00
parent 968b967854
commit 810374d648
4 changed files with 21 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
import { theme } from "../terminal/theme.js";
export type HelpExample = [command: string, description: string];
export type HelpExample = readonly [command: string, description: string];
export function formatHelpExample(command: string, description: string): string {
return ` ${theme.command(command)}\n ${theme.muted(description)}`;
@@ -11,11 +11,15 @@ export function formatHelpExampleLine(command: string, description: string): str
return ` ${theme.command(command)} ${theme.muted(`# ${description}`)}`;
}
export function formatHelpExamples(examples: HelpExample[], inline = false): string {
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: HelpExample[], inline = false) {
export function formatHelpExampleGroup(
label: string,
examples: ReadonlyArray<HelpExample>,
inline = false,
) {
return `${theme.muted(label)}\n${formatHelpExamples(examples, inline)}`;
}