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

@@ -30,6 +30,11 @@ function buildRows(entries: Array<{ id: string; name?: string | undefined }>) {
})); }));
} }
function formatEntry(entry: { id: string; name?: string | undefined }) {
const name = entry.name?.trim();
return name ? `${entry.id} ${theme.muted(name)}` : entry.id;
}
export function registerDirectoryCli(program: Command) { export function registerDirectoryCli(program: Command) {
const directory = program const directory = program
.command("directory") .command("directory")

View File

@@ -7,6 +7,8 @@ describe("dns cli", () => {
const log = vi.spyOn(console, "log").mockImplementation(() => {}); const log = vi.spyOn(console, "log").mockImplementation(() => {});
const program = buildProgram(); const program = buildProgram();
await program.parseAsync(["dns", "setup"], { from: "user" }); await program.parseAsync(["dns", "setup"], { from: "user" });
expect(log).toHaveBeenCalledWith(expect.stringContaining("Domain:")); const output = log.mock.calls.map((call) => call.join(" ")).join("\n");
expect(output).toContain("DNS setup");
expect(output).toContain("clawdbot.internal");
}); });
}); });

View File

@@ -1,6 +1,6 @@
import { theme } from "../terminal/theme.js"; 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 { export function formatHelpExample(command: string, description: string): string {
return ` ${theme.command(command)}\n ${theme.muted(description)}`; 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}`)}`; 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; const formatter = inline ? formatHelpExampleLine : formatHelpExample;
return examples.map(([command, description]) => formatter(command, description)).join("\n"); 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)}`; return `${theme.muted(label)}\n${formatHelpExamples(examples, inline)}`;
} }

View File

@@ -71,7 +71,9 @@ describe("pairing cli", () => {
await program.parseAsync(["pairing", "list", "--channel", "telegram"], { await program.parseAsync(["pairing", "list", "--channel", "telegram"], {
from: "user", from: "user",
}); });
expect(log).toHaveBeenCalledWith(expect.stringContaining("telegramUserId=123")); const output = log.mock.calls.map((call) => call.join(" ")).join("\n");
expect(output).toContain("telegramUserId");
expect(output).toContain("123");
}); });
it("accepts channel as positional for list", async () => { it("accepts channel as positional for list", async () => {
@@ -131,7 +133,9 @@ describe("pairing cli", () => {
await program.parseAsync(["pairing", "list", "--channel", "discord"], { await program.parseAsync(["pairing", "list", "--channel", "discord"], {
from: "user", from: "user",
}); });
expect(log).toHaveBeenCalledWith(expect.stringContaining("discordUserId=999")); const output = log.mock.calls.map((call) => call.join(" ")).join("\n");
expect(output).toContain("discordUserId");
expect(output).toContain("999");
}); });
it("accepts channel as positional for approve (npm-run compatible)", async () => { it("accepts channel as positional for approve (npm-run compatible)", async () => {