mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Address review of ctl --output
Add a wire output format that prints the toJSON format sent over the link. Commands without a result print {"success": true}, or "Command ran successfully" in human mode. The missing URL check throws a StartupError, unexpected command errors are rethrown to the startup handler, and startup errors log as fatal. user list, note list and host plugin list print the objects they received instead of their table rows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
10beffe167
commit
8550df69eb
13 files changed
+131
-112
No files matched your search
@@ -43,6 +43,9 @@ describe("ctl/command_ops", function() {
|
||||
assert.deepEqual(captureLog(() => output.result({ a: 1 }, human)), ["human"]);
|
||||
assert.deepEqual(captureLog(() => output.finish()), []);
|
||||
});
|
||||
it("prints a success line in human mode for commands without a result", function() {
|
||||
assert.deepEqual(captureLog(() => new CommandOutput("human").finish()), ["Command ran successfully"]);
|
||||
});
|
||||
it("prints one line of JSON per result in json mode", function() {
|
||||
const output = new CommandOutput("json");
|
||||
const lines = captureLog(() => {
|
||||
@@ -52,8 +55,14 @@ describe("ctl/command_ops", function() {
|
||||
});
|
||||
assert.deepEqual(lines, ['{"a":[1]}', '[{"b":2}]']);
|
||||
});
|
||||
it("prints {} for commands without a result", function() {
|
||||
assert.deepEqual(captureLog(() => new CommandOutput("json").finish()), ["{}"]);
|
||||
it("prints the toJSON format in wire mode", function() {
|
||||
const output = new CommandOutput("wire");
|
||||
const role = new lib.Role(1, "name", "desc", new Set(["core.admin"]));
|
||||
const lines = captureLog(() => output.result({ role, set: new Set([1]), map: new Map([["a", 2]]) }));
|
||||
assert.deepEqual(JSON.parse(lines[0]), { role: JSON.parse(JSON.stringify(role)), set: [1], map: { a: 2 } });
|
||||
});
|
||||
it("prints success for commands without a result", function() {
|
||||
assert.deepEqual(captureLog(() => new CommandOutput("json").finish()), ['{"success":true}']);
|
||||
const streaming = new CommandOutput("json");
|
||||
streaming.streaming = true;
|
||||
assert.deepEqual(captureLog(() => streaming.finish()), []);
|
||||
|
||||
@@ -2326,7 +2326,18 @@ describe("Integration of Clusterio", function() {
|
||||
const { id } = JSON.parse(await execCtlOutput("--output json role create json-role"));
|
||||
const roles = await getControl().send(new lib.RoleListRequest());
|
||||
assert.equal(roles.find(role => role.id === id)?.name, "json-role");
|
||||
assert.equal(await execCtlOutput(`--output json role delete ${id}`), "{}");
|
||||
assert.equal(await execCtlOutput(`--output json role delete ${id}`), '{"success":true}');
|
||||
});
|
||||
it("prints the toJSON format in wire mode", async function() {
|
||||
const [jsonUser] = JSON.parse(await execCtlOutput("--output json user list"));
|
||||
const [wireUser] = JSON.parse(await execCtlOutput("--output wire user list"));
|
||||
assert("roleIds" in jsonUser);
|
||||
assert(!("roleIds" in wireUser));
|
||||
assert.equal(wireUser.name, jsonUser.name);
|
||||
});
|
||||
it("prints a success line for commands without a result", async function() {
|
||||
const { id } = JSON.parse(await execCtlOutput("--output json role create human-role"));
|
||||
assert.equal(await execCtlOutput(`role delete ${id}`), "Command ran successfully");
|
||||
});
|
||||
it("prints log queries as an array", async function() {
|
||||
const log = JSON.parse(await execCtlOutput("--output json log query --controller --limit 1"));
|
||||
|
||||
Reference in new issue
Block a user