From 8acb54985c7bc5cabadaf8ebb8956f954c076460 Mon Sep 17 00:00:00 2001 From: Bastiaan <17990055+bbassie@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:44:39 +0100 Subject: [PATCH] Print Set values in ctl tables as lists (#1213) user list, user show and role list passed UserDetails and Role objects straight to as-table, whose default String() turns the roleIds, instances and permissions Sets into "[object Set]". Move the as-table setup into command_ops.ts with a cell printer that joins Sets with ", ", and use it for the user and role commands. The integration tests for role list and user list now capture the output and check it. Co-authored-by: Claude Opus 5.5 --- packages/ctl/src/command_ops.ts | 11 +++++++++++ packages/ctl/src/commands_role.ts | 5 +---- packages/ctl/src/commands_user.ts | 5 +---- test/integration/clusterio.js | 12 ++++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/ctl/src/command_ops.ts b/packages/ctl/src/command_ops.ts index 24d13c69..88e9a7e3 100644 --- a/packages/ctl/src/command_ops.ts +++ b/packages/ctl/src/command_ops.ts @@ -1,4 +1,15 @@ +import asTableModule from "as-table"; + export function print(...content: any) { // eslint-disable-next-line no-console console.log(...content); } + +function formatCell(value: unknown) { + if (value instanceof Set) { + return [...value].join(", "); + } + return String(value); +} + +export const asTable = asTableModule.configure({ delimiter: " | ", print: formatCell }); diff --git a/packages/ctl/src/commands_role.ts b/packages/ctl/src/commands_role.ts index 2b6a42cd..80893d8f 100644 --- a/packages/ctl/src/commands_role.ts +++ b/packages/ctl/src/commands_role.ts @@ -1,11 +1,8 @@ -import asTableModule from "as-table"; import * as lib from "@clusterio/lib"; import { logger } from "@clusterio/lib"; import type { Ctl } from "../ctl.js"; -import { print } from "./command_ops.js"; - -const asTable = asTableModule.configure({ delimiter: " | " }); +import { asTable, print } from "./command_ops.js"; export const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" }); roleCommands.add(new lib.Command({ diff --git a/packages/ctl/src/commands_user.ts b/packages/ctl/src/commands_user.ts index 6df05c22..14235c99 100644 --- a/packages/ctl/src/commands_user.ts +++ b/packages/ctl/src/commands_user.ts @@ -1,12 +1,9 @@ import fs from "node:fs/promises"; -import asTableModule from "as-table"; import path from "path"; import * as lib from "@clusterio/lib"; import type { Ctl } from "../ctl.js"; -import { print } from "./command_ops.js"; - -const asTable = asTableModule.configure({ delimiter: " | " }); +import { asTable, print } from "./command_ops.js"; export const userCommands = new lib.CommandTree({ name: "user", alias: ["u"], description: "User management" }); userCommands.add(new lib.Command({ diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index db4c34d8..5ac99976 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -2204,8 +2204,10 @@ describe("Integration of Clusterio", function() { }); describe("role list", function() { - it("runs", async function() { - await execCtl("role list"); + it("prints permissions as a list", async function() { + const output = await execCtlOutput("role list"); + assert(!output.includes("[object"), output); + assert.match(output, /Cluster Admin .*core\.admin/); }); }); @@ -2316,8 +2318,10 @@ describe("Integration of Clusterio", function() { }); describe("user list", function() { - it("runs", async function() { - await execCtl("user list"); + it("prints roles and instances as lists", async function() { + const output = await execCtlOutput("user list"); + assert(!output.includes("[object"), output); + assert.match(output, /roleIds/); }); });