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 <noreply@anthropic.com>
This commit is contained in:
BastiaanandClaude Opus 5.5 authored and GitHub committed 2026-11-17 10:44:39 +00:00
1 parent ec2bc6504b
commit 8acb54985c
4 files changed
+21 -12

No files matched your search

+11
View File
@@ -1,4 +1,15 @@
import asTableModule from "as-table";
export function print(...content: any) { export function print(...content: any) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(...content); 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 });
+1 -4
View File
@@ -1,11 +1,8 @@
import asTableModule from "as-table";
import * as lib from "@clusterio/lib"; import * as lib from "@clusterio/lib";
import { logger } from "@clusterio/lib"; import { logger } from "@clusterio/lib";
import type { Ctl } from "../ctl.js"; import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js"; import { asTable, print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
export const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" }); export const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" });
roleCommands.add(new lib.Command({ roleCommands.add(new lib.Command({
+1 -4
View File
@@ -1,12 +1,9 @@
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import asTableModule from "as-table";
import path from "path"; import path from "path";
import * as lib from "@clusterio/lib"; import * as lib from "@clusterio/lib";
import type { Ctl } from "../ctl.js"; import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js"; import { asTable, print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
export const userCommands = new lib.CommandTree({ name: "user", alias: ["u"], description: "User management" }); export const userCommands = new lib.CommandTree({ name: "user", alias: ["u"], description: "User management" });
userCommands.add(new lib.Command({ userCommands.add(new lib.Command({
+8 -4
View File
@@ -2204,8 +2204,10 @@ describe("Integration of Clusterio", function() {
}); });
describe("role list", function() { describe("role list", function() {
it("runs", async function() { it("prints permissions as a list", async function() {
await execCtl("role list"); 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() { describe("user list", function() {
it("runs", async function() { it("prints roles and instances as lists", async function() {
await execCtl("user list"); const output = await execCtlOutput("user list");
assert(!output.includes("[object"), output);
assert.match(output, /roleIds/);
}); });
}); });