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/); }); });