Skip to content

Commit 310d227

Browse files
authored
fix: add header to list response (#6)
1 parent e190951 commit 310d227

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

.changeset/cuddly-taxis-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@upstash/box": patch
3+
---
4+
5+
Bump version to trigger release workflow

.changeset/icy-tables-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@upstash/box-cli": patch
3+
---
4+
5+
Add header to list response

packages/cli/src/__tests__/commands/list.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ describe("listCommand", () => {
3131

3232
await listCommand({ token: "key" });
3333

34-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("box-1"));
35-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("box-2"));
34+
const calls = logSpy.mock.calls.map((c: unknown[]) => c[0]);
35+
expect(calls[0]).toMatch(/^ID\s+STATUS\s+MODEL\s+CREATED/);
36+
expect(calls[1]).toMatch(/^box-1\s+running\s+claude\s+2025-01-01/);
37+
expect(calls[2]).toMatch(/^box-2\s+stopped\s+gpt\s+2025-01-02/);
3638
});
3739

3840
it("prints message when empty", async () => {

packages/cli/src/commands/list.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@ export async function listCommand(flags: ListFlags): Promise<void> {
1515
return;
1616
}
1717

18-
for (const b of boxes) {
19-
console.log(`${b.id}\t${b.status}\t${b.model}\t${b.created_at}`);
18+
const headers = ["ID", "STATUS", "MODEL", "CREATED"];
19+
const rows = boxes.map((b) => [b.id, b.status, b.model ?? "", String(b.created_at)]);
20+
21+
const colWidths = headers.map((h, i) =>
22+
Math.max(h.length, ...rows.map((r) => r[i]!.length))
23+
);
24+
25+
const formatRow = (row: string[]) =>
26+
row.map((val, i) => val.padEnd(colWidths[i]!)).join(" ");
27+
28+
console.log(formatRow(headers));
29+
for (const row of rows) {
30+
console.log(formatRow(row));
2031
}
2132
}

0 commit comments

Comments
 (0)