mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
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:
1 parent
ec2bc6504b
commit
8acb54985c
4 files changed
+21
-12
No files matched your search
@@ -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 });
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user