Rename Ctl's usage of "control" to "ctl" (#1039)

Ctl ended up calling its main class for "Control" for historical
reasons, along with its config file and plugin entrypoint.

The plugin entrypoint was renamed to ctl in 808eda0513.  This
finishes that renaming by also renaming the main class, default config
file, config-control command, and main entrypoint.

The config-control command is renamed to config to be consistent with
the host and controller's config commands.

The term "control" is still kept in the config and message locations as
a common specifier for both ctl and web_ui.
This commit is contained in:
Hornwitser authored and GitHub committed 2026-09-14 20:18:41 +02:00
1 parent 1d1d9bb1c4
commit 5df5af7ca8
35 files changed
+383 -383

No files matched your search

+26 -26
View File
@@ -5,7 +5,7 @@ import os from "os";
import child_process from "child_process";
import * as lib from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
import { serializedConfigToString, getEditor, configToKeyVal } from "./config_ops.js";
@@ -14,15 +14,15 @@ const asTable = asTableModule.configure({ delimiter: " | " });
export const controllerCommands = new lib.CommandTree({ name: "controller", description: "Controller management" });
controllerCommands.add(new lib.Command({
definition: ["stop", "Stop controller"],
handler: async function(_args: object, control: Control) {
await control.send(new lib.ControllerStopRequest());
handler: async function(_args: object, ctl: Ctl) {
await ctl.send(new lib.ControllerStopRequest());
},
}));
controllerCommands.add(new lib.Command({
definition: ["restart", "Restart controller"],
handler: async function(_args: object, control: Control) {
await control.send(new lib.ControllerRestartRequest());
handler: async function(_args: object, ctl: Ctl) {
await ctl.send(new lib.ControllerRestartRequest());
},
}));
controllerCommands.add(new lib.Command({
@@ -30,14 +30,14 @@ controllerCommands.add(new lib.Command({
yargs.option("restart", { alias: "r", type: "boolean", description: "Restart after update" });
yargs.option("all", { alias: "a", type: "boolean", description: "Also update all plugins" });
}],
handler: async function(args: { restart: boolean, all: boolean }, control: Control) {
handler: async function(args: { restart: boolean, all: boolean }, ctl: Ctl) {
if (args.all) {
await control.send(new lib.UpdateAllRequest());
await ctl.send(new lib.UpdateAllRequest());
} else {
await control.send(new lib.ControllerUpdateRequest());
await ctl.send(new lib.ControllerUpdateRequest());
}
if (args.restart) {
await control.send(new lib.ControllerRestartRequest());
await ctl.send(new lib.ControllerRestartRequest());
} else {
print("Controller updated; a restart is required to apply the changes.");
}
@@ -50,8 +50,8 @@ const controllerConfigCommands = new lib.CommandTree({
controllerConfigCommands.add(new lib.Command({
definition: ["list", "List controller configuration"],
handler: async function(args: object, control: Control) {
let config = await control.send(new lib.ControllerConfigGetRequest());
handler: async function(args: object, ctl: Ctl) {
let config = await ctl.send(new lib.ControllerConfigGetRequest());
for (let [name, value] of Object.entries(config)) {
print(`${name} ${JSON.stringify(value)}`);
@@ -67,13 +67,13 @@ controllerConfigCommands.add(new lib.Command({
"stdin": { describe: "read value from stdin", nargs: 0, type: "boolean" },
});
}],
handler: async function(args: { field: string, value?: string, stdin?: boolean }, control: Control) {
handler: async function(args: { field: string, value?: string, stdin?: boolean }, ctl: Ctl) {
if (args.stdin) {
args.value = (await lib.readStream(process.stdin)).toString().replace(/\r?\n$/, "");
} else if (args.value === undefined) {
args.value = "";
}
await control.send(new lib.ControllerConfigSetFieldRequest(args.field, args.value));
await ctl.send(new lib.ControllerConfigSetFieldRequest(args.field, args.value));
},
}));
@@ -86,7 +86,7 @@ controllerConfigCommands.add(new lib.Command({
"stdin": { describe: "read value from stdin", nargs: 0, type: "boolean" },
});
}],
handler: async function(args: { field: string, prop: string, value?: string, stdin?: boolean }, control: Control) {
handler: async function(args: { field: string, prop: string, value?: string, stdin?: boolean }, ctl: Ctl) {
if (args.stdin) {
args.value = (await lib.readStream(process.stdin)).toString().replace(/\r?\n$/, "");
}
@@ -102,7 +102,7 @@ controllerConfigCommands.add(new lib.Command({
}
value = args.value;
}
await control.send(new lib.ControllerConfigSetPropRequest(args.field, args.prop, value));
await ctl.send(new lib.ControllerConfigSetPropRequest(args.field, args.prop, value));
},
}));
controllerConfigCommands.add(new lib.Command({
@@ -113,8 +113,8 @@ controllerConfigCommands.add(new lib.Command({
default: "",
});
}],
handler: async function(args: { editor: string }, control: Control) {
let config = await control.send(new lib.ControllerConfigGetRequest());
handler: async function(args: { editor: string }, ctl: Ctl) {
let config = await ctl.send(new lib.ControllerConfigGetRequest());
let tmpFile = await lib.getTempFile("ctl-", "-tmp", os.tmpdir());
let editor = await getEditor(args.editor);
if (editor === undefined) {
@@ -138,7 +138,7 @@ controllerConfigCommands.add(new lib.Command({
for (let index in final) {
if (index in final) {
try {
await control.send(new lib.ControllerConfigSetFieldRequest(
await ctl.send(new lib.ControllerConfigSetFieldRequest(
index,
final[index],
));
@@ -167,8 +167,8 @@ const controllerPluginCommands = new lib.CommandTree({
});
controllerPluginCommands.add(new lib.Command({
definition: ["list", "List plugins on controller"],
handler: async function(args: object, control: Control) {
let url = new URL(control.config.get("control.controller_url")!);
handler: async function(args: object, ctl: Ctl) {
let url = new URL(ctl.config.get("ctl.controller_url")!);
url.pathname += "api/plugins";
let response = await fetch(url);
print(asTable(await response.json() as []));
@@ -179,10 +179,10 @@ controllerPluginCommands.add(new lib.Command({
yargs.positional("plugin", { describe: "Plugin to update", type: "string" });
yargs.option("restart", { alias: "r", type: "boolean", description: "Restart after update" });
}],
handler: async function(args: { plugin: string, restart: boolean }, control: Control) {
await control.sendTo("controller", new lib.PluginUpdateRequest(args.plugin));
handler: async function(args: { plugin: string, restart: boolean }, ctl: Ctl) {
await ctl.sendTo("controller", new lib.PluginUpdateRequest(args.plugin));
if (args.restart) {
await control.send(new lib.ControllerRestartRequest());
await ctl.send(new lib.ControllerRestartRequest());
} else {
print("Plugin updated; a restart is required to apply the changes.");
}
@@ -193,10 +193,10 @@ controllerPluginCommands.add(new lib.Command({
yargs.positional("plugin", { describe: "Plugin to install", type: "string" });
yargs.option("restart", { alias: "r", type: "boolean", description: "Restart after update" });
}],
handler: async function(args: { plugin: string, restart: boolean }, control: Control) {
await control.sendTo("controller", new lib.PluginInstallRequest(args.plugin));
handler: async function(args: { plugin: string, restart: boolean }, ctl: Ctl) {
await ctl.sendTo("controller", new lib.PluginInstallRequest(args.plugin));
if (args.restart) {
await control.send(new lib.ControllerRestartRequest());
await ctl.send(new lib.ControllerRestartRequest());
} else {
print("Plugin installed; a restart is required to apply the changes.");
}
+5 -5
View File
@@ -1,12 +1,12 @@
import * as lib from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
export const debugCommands = new lib.CommandTree({ name: "debug", description: "Debugging utilities" });
debugCommands.add(new lib.Command({
definition: ["dump-ws", "Dump WebSocket messages sent and received by controller"],
handler: async function(args: object, control: Control) {
await control.send(new lib.DebugDumpWsRequest());
control.keepOpen = true;
handler: async function(args: object, ctl: Ctl) {
await ctl.send(new lib.DebugDumpWsRequest());
ctl.keepOpen = true;
},
}));
@@ -18,7 +18,7 @@ debugCommands.add(new lib.Command({
yargs.positional("exchange-string", { describe: "String to parse", type: "string" });
yargs.option("pretty", { alias: "p", type: "boolean", description: "Pretty output" });
}],
handler: async function(args: { exchangeString: string, pretty: boolean }, control: Control) {
handler: async function(args: { exchangeString: string, pretty: boolean }, ctl: Ctl) {
const result = lib.readMapExchangeString(args.exchangeString);
if (args.pretty) {
// eslint-disable-next-line no-console
+45 -45
View File
@@ -6,7 +6,7 @@ import child_process from "child_process";
import * as lib from "@clusterio/lib";
import { logger } from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
import { serializedConfigToString, getEditor, configToKeyVal } from "./config_ops.js";
@@ -17,9 +17,9 @@ hostCommands.add(new lib.Command({
definition: ["stop <host>", "Stop the given host", (yargs) => {
yargs.positional("host", { describe: "Host to stop", type: "string" });
}],
handler: async function(args: { host: string }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
await control.sendTo({ hostId }, new lib.HostStopRequest());
handler: async function(args: { host: string }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
await ctl.sendTo({ hostId }, new lib.HostStopRequest());
},
}));
@@ -27,16 +27,16 @@ hostCommands.add(new lib.Command({
definition: ["restart <host>", "Restart the given host", (yargs) => {
yargs.positional("host", { describe: "Host to restart", type: "string" });
}],
handler: async function(args: { host: string }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
await control.sendTo({ hostId }, new lib.HostRestartRequest());
handler: async function(args: { host: string }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
await ctl.sendTo({ hostId }, new lib.HostRestartRequest());
},
}));
hostCommands.add(new lib.Command({
definition: [["list", "l"], "List hosts connected to the controller"],
handler: async function(args: object, control: Control) {
let hosts = await control.send(new lib.HostListRequest());
handler: async function(args: object, ctl: Ctl) {
let hosts = await ctl.send(new lib.HostListRequest());
print(asTable(hosts));
},
}));
@@ -45,9 +45,9 @@ hostCommands.add(new lib.Command({
definition: ["generate-token", "Generate token for a host", (yargs) => {
yargs.option("id", { type: "number", nargs: 1, describe: "Host id" });
}],
handler: async function(args: { id?: number }, control: Control) {
handler: async function(args: { id?: number }, ctl: Ctl) {
let hostId = typeof args.id === "number" ? args.id : undefined;
let response = await control.send(new lib.HostGenerateTokenRequest(hostId));
let response = await ctl.send(new lib.HostGenerateTokenRequest(hostId));
print(response);
},
}));
@@ -56,9 +56,9 @@ hostCommands.add(new lib.Command({
definition: ["revoke-token <host>", "Revoke all tokens for a host", (yargs) => {
yargs.positional("host", { describe: "Host to revoke tokens for", type: "string" });
}],
handler: async function(args: { host: string }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
await control.send(new lib.HostRevokeTokensRequest(hostId));
handler: async function(args: { host: string }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
await ctl.send(new lib.HostRevokeTokensRequest(hostId));
},
}));
@@ -75,9 +75,9 @@ hostCommands.add(new lib.Command({
}],
handler: async function(
args: { id?: number, name?: string, generateToken: boolean, output: string },
control: Control
ctl: Ctl
) {
let config = await control.send(
let config = await ctl.send(
new lib.HostConfigCreateRequest(args.id, args.name, args.generateToken)
);
@@ -103,15 +103,15 @@ hostCommands.add(new lib.Command({
yargs.option("restart", { alias: "r", type: "boolean", description: "Restart after update" });
yargs.option("all", { alias: "a", type: "boolean", description: "Also update all plugins" });
}],
handler: async function(args: { host: string, restart: boolean, all: boolean }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
handler: async function(args: { host: string, restart: boolean, all: boolean }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
if (args.all) {
await control.sendTo({ hostId }, new lib.UpdateAllRequest());
await ctl.sendTo({ hostId }, new lib.UpdateAllRequest());
} else {
await control.sendTo({ hostId }, new lib.HostUpdateRequest());
await ctl.sendTo({ hostId }, new lib.HostUpdateRequest());
}
if (args.restart) {
await control.sendTo({ hostId }, new lib.HostRestartRequest());
await ctl.sendTo({ hostId }, new lib.HostRestartRequest());
} else {
print("Host updated; a restart is required to apply the changes.");
}
@@ -126,9 +126,9 @@ hostConfigCommands.add(new lib.Command({
definition: ["list <host>", "List configuration for a host", (yargs) => {
yargs.positional("host", { describe: "Host to list config for", type: "string" });
}],
handler: async function(args: { host: string }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
let config = await control.sendTo({ hostId }, new lib.HostConfigGetRequest());
handler: async function(args: { host: string }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
let config = await ctl.sendTo({ hostId }, new lib.HostConfigGetRequest());
for (let [name, value] of Object.entries(config)) {
print(`${name} ${JSON.stringify(value)}`);
@@ -147,15 +147,15 @@ hostConfigCommands.add(new lib.Command({
}],
handler: async function(
args: { host: string, field: string, value?: string, stdin?: boolean },
control: Control,
ctl: Ctl,
) {
let hostId = await lib.resolveHost(control, args.host);
let hostId = await lib.resolveHost(ctl, args.host);
if (args.stdin) {
args.value = (await lib.readStream(process.stdin)).toString().replace(/\r?\n$/, "");
} else if (args.value === undefined) {
args.value = "";
}
await control.sendTo({ hostId }, new lib.HostConfigSetFieldRequest(args.field, args.value));
await ctl.sendTo({ hostId }, new lib.HostConfigSetFieldRequest(args.field, args.value));
},
}));
@@ -171,9 +171,9 @@ hostConfigCommands.add(new lib.Command({
}],
handler: async function(
args: { host: string, field: string, prop: string, value?: string, stdin?: boolean },
control: Control
ctl: Ctl
) {
let hostId = await lib.resolveHost(control, args.host);
let hostId = await lib.resolveHost(ctl, args.host);
if (args.stdin) {
args.value = (await lib.readStream(process.stdin)).toString().replace(/\r?\n$/, "");
}
@@ -189,7 +189,7 @@ hostConfigCommands.add(new lib.Command({
}
value = args.value;
}
await control.sendTo({ hostId }, new lib.HostConfigSetPropRequest(args.field, args.prop, value));
await ctl.sendTo({ hostId }, new lib.HostConfigSetPropRequest(args.field, args.prop, value));
},
}));
@@ -202,9 +202,9 @@ hostConfigCommands.add(new lib.Command({
default: "",
});
}],
handler: async function(args: { host: string, editor: string }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
let config = await control.sendTo({ hostId }, new lib.HostConfigGetRequest());
handler: async function(args: { host: string, editor: string }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
let config = await ctl.sendTo({ hostId }, new lib.HostConfigGetRequest());
let tmpFile = await lib.getTempFile("ctl-", "-tmp", os.tmpdir());
let editor = await getEditor(args.editor);
if (editor === undefined) {
@@ -231,7 +231,7 @@ hostConfigCommands.add(new lib.Command({
for (let index in final) {
if (index in final) {
try {
await control.sendTo({ hostId }, new lib.HostConfigSetFieldRequest(
await ctl.sendTo({ hostId }, new lib.HostConfigSetFieldRequest(
index,
final[index],
));
@@ -267,9 +267,9 @@ hostPluginCommands.add(new lib.Command({
definition: ["list <host>", "List plugins on a host", (yargs) => {
yargs.positional("host", { describe: "Host to list for", type: "string" });
}],
handler: async function(args: { host: string }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
const plugins = await control.sendTo({ hostId }, new lib.PluginListRequest());
handler: async function(args: { host: string }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
const plugins = await ctl.sendTo({ hostId }, new lib.PluginListRequest());
print(asTable(plugins.map(p => ({
title: p.title, version: p.version, loaded: p.loaded, enabled: p.enabled, npmPackage: p.npmPackage,
}))));
@@ -281,11 +281,11 @@ hostPluginCommands.add(new lib.Command({
yargs.positional("plugin", { describe: "Plugin to update", type: "string" });
yargs.option("restart", { alias: "r", type: "boolean", description: "Restart after update" });
}],
handler: async function(args: { host: string, plugin: string, restart: boolean }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
await control.sendTo({ hostId }, new lib.PluginUpdateRequest(args.plugin));
handler: async function(args: { host: string, plugin: string, restart: boolean }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
await ctl.sendTo({ hostId }, new lib.PluginUpdateRequest(args.plugin));
if (args.restart) {
await control.sendTo({ hostId }, new lib.HostRestartRequest());
await ctl.sendTo({ hostId }, new lib.HostRestartRequest());
} else {
print("Plugin updated; a restart is required to apply the changes.");
}
@@ -297,11 +297,11 @@ hostPluginCommands.add(new lib.Command({
yargs.positional("plugin", { describe: "Plugin to install", type: "string" });
yargs.option("restart", { alias: "r", type: "boolean", description: "Restart after update" });
}],
handler: async function(args: { host: string, plugin: string, restart: boolean }, control: Control) {
let hostId = await lib.resolveHost(control, args.host);
await control.sendTo({ hostId }, new lib.PluginInstallRequest(args.plugin));
handler: async function(args: { host: string, plugin: string, restart: boolean }, ctl: Ctl) {
let hostId = await lib.resolveHost(ctl, args.host);
await ctl.sendTo({ hostId }, new lib.PluginInstallRequest(args.plugin));
if (args.restart) {
await control.sendTo({ hostId }, new lib.HostRestartRequest());
await ctl.sendTo({ hostId }, new lib.HostRestartRequest());
} else {
print("Plugin installed; a restart is required to apply the changes.");
}
+96 -96
View File
@@ -9,7 +9,7 @@ import util from "util";
import * as lib from "@clusterio/lib";
import { logger } from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
import { serializedConfigToString, getEditor, configToKeyVal } from "./config_ops.js";
@@ -21,8 +21,8 @@ export const instanceCommands = new lib.CommandTree({
});
instanceCommands.add(new lib.Command({
definition: [["list", "l"], "List instances known to the controller"],
handler: async function(args: object, control: Control) {
let list = await control.send(new lib.InstanceDetailsListRequest());
handler: async function(args: object, ctl: Ctl) {
let list = await ctl.send(new lib.InstanceDetailsListRequest());
print(asTable(list));
},
}));
@@ -36,13 +36,13 @@ instanceCommands.add(new lib.Command({
"from": { type: "number", nargs: 1, describe: "Clone config from instance id" },
});
}],
handler: async function(args: { name: string, id?: number, from?: number, }, control: Control) {
handler: async function(args: { name: string, id?: number, from?: number, }, ctl: Ctl) {
let instanceConfig = new lib.InstanceConfig("control");
if (args.id !== undefined) {
instanceConfig.set("instance.id", args.id);
}
instanceConfig.set("instance.name", args.name);
await control.send(new lib.InstanceCreateRequest(
await ctl.send(new lib.InstanceCreateRequest(
instanceConfig.toRemote("controller", [
"instance.id", "instance.name",
]),
@@ -58,9 +58,9 @@ instanceConfigCommands.add(new lib.Command({
definition: ["list <instance>", "List configuration for an instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to list config for", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
let config = await control.send(new lib.InstanceConfigGetRequest(instanceId));
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
let config = await ctl.send(new lib.InstanceConfigGetRequest(instanceId));
for (let [name, value] of Object.entries(config)) {
print(`${name} ${JSON.stringify(value)}`);
@@ -79,15 +79,15 @@ instanceConfigCommands.add(new lib.Command({
}],
handler: async function(
args: { instance: string, field: string, value?: string, stdin?: boolean },
control: Control,
ctl: Ctl,
) {
let instanceId = await lib.resolveInstance(control, args.instance);
let instanceId = await lib.resolveInstance(ctl, args.instance);
if (args.stdin) {
args.value = (await lib.readStream(process.stdin)).toString().replace(/\r?\n$/, "");
} else if (args.value === undefined) {
args.value = "";
}
await control.send(new lib.InstanceConfigSetFieldRequest(instanceId, args.field, args.value));
await ctl.send(new lib.InstanceConfigSetFieldRequest(instanceId, args.field, args.value));
},
}));
@@ -103,9 +103,9 @@ instanceConfigCommands.add(new lib.Command({
}],
handler: async function(
args: { instance: string, field: string, prop: string, value?: string, stdin?: boolean },
control: Control
ctl: Ctl
) {
let instanceId = await lib.resolveInstance(control, args.instance);
let instanceId = await lib.resolveInstance(ctl, args.instance);
if (args.stdin) {
args.value = (await lib.readStream(process.stdin)).toString().replace(/\r?\n$/, "");
}
@@ -136,7 +136,7 @@ instanceConfigCommands.add(new lib.Command({
}
value = args.value;
}
await control.send(new lib.InstanceConfigSetPropRequest(instanceId, args.field, args.prop, value));
await ctl.send(new lib.InstanceConfigSetPropRequest(instanceId, args.field, args.prop, value));
},
}));
@@ -149,9 +149,9 @@ instanceConfigCommands.add(new lib.Command({
default: "",
});
}],
handler: async function(args: { instance: string, editor: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
let config = await control.send(new lib.InstanceConfigGetRequest(instanceId));
handler: async function(args: { instance: string, editor: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
let config = await ctl.send(new lib.InstanceConfigGetRequest(instanceId));
let tmpFile = await lib.getTempFile("ctl-", "-tmp", os.tmpdir());
let editor = await getEditor(args.editor);
if (editor === undefined) {
@@ -178,7 +178,7 @@ instanceConfigCommands.add(new lib.Command({
for (let index in final) {
if (index in final) {
try {
await control.send(new lib.InstanceConfigSetFieldRequest(
await ctl.send(new lib.InstanceConfigSetFieldRequest(
instanceId,
index,
final[index],
@@ -211,10 +211,10 @@ instanceCommands.add(new lib.Command({
yargs.positional("instance", { describe: "Instance to assign", type: "string" });
yargs.positional("host", { describe: "Host to assign to or unassign if none", type: "string" });
}],
handler: async function(args: { instance: string, host?: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
let hostId = args.host ? await lib.resolveHost(control, args.host) : undefined;
await control.send(new lib.InstanceAssignRequest(instanceId, hostId));
handler: async function(args: { instance: string, host?: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
let hostId = args.host ? await lib.resolveHost(ctl, args.host) : undefined;
await ctl.send(new lib.InstanceAssignRequest(instanceId, hostId));
},
}));
@@ -250,9 +250,9 @@ instanceSaveCommands.add(new lib.Command({
definition: ["list <instance>", "list saves on an instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to list saves on", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
let saves = await control.sendTo("controller", new lib.InstanceSaveDetailsListRequest());
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
let saves = await ctl.sendTo("controller", new lib.InstanceSaveDetailsListRequest());
saves = saves.filter(save => save.instanceId === instanceId);
print(asTable(saves.map(
({ mtimeMs, ...rest }) => ({ ...rest, mtime: new Date(mtimeMs).toLocaleString() })
@@ -280,12 +280,12 @@ instanceSaveCommands.add(new lib.Command({
mapGenSettings?: string,
mapSettings?: string,
},
control: Control
ctl: Ctl
) {
let instanceId = await lib.resolveInstance(control, args.instance);
let instanceId = await lib.resolveInstance(ctl, args.instance);
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo(
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo(
{ instanceId },
new lib.InstanceCreateSaveRequest(args.name, seed, mapGenSettings, mapSettings),
);
@@ -298,9 +298,9 @@ instanceSaveCommands.add(new lib.Command({
yargs.positional("old-name", { describe: "Old name of save.", type: "string" });
yargs.positional("new-name", { describe: "New name of save.", type: "string" });
}],
handler: async function(args: { instance: string, oldName: string, newName: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.send(new lib.InstanceRenameSaveRequest(instanceId, args.oldName, args.newName));
handler: async function(args: { instance: string, oldName: string, newName: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.send(new lib.InstanceRenameSaveRequest(instanceId, args.oldName, args.newName));
},
}));
@@ -310,9 +310,9 @@ instanceSaveCommands.add(new lib.Command({
yargs.positional("source", { describe: "Save to copy.", type: "string" });
yargs.positional("destination", { describe: "Name of copy.", type: "string" });
}],
handler: async function(args: { instance: string, source: string, destination: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.send(new lib.InstanceCopySaveRequest(instanceId, args.source, args.destination));
handler: async function(args: { instance: string, source: string, destination: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.send(new lib.InstanceCopySaveRequest(instanceId, args.source, args.destination));
},
}));
@@ -324,14 +324,14 @@ instanceSaveCommands.add(new lib.Command({
"name": { describe: "Name to give save on server", nargs: 1, type: "string" },
});
}],
handler: async function(args: { instance: string, filepath: string, name?: string }, control: Control) {
handler: async function(args: { instance: string, filepath: string, name?: string }, ctl: Ctl) {
let filename = args.name || path.basename(args.filepath);
if (!filename.endsWith(".zip")) {
throw new lib.CommandError("Save name must end with .zip");
}
let instanceId = await lib.resolveInstance(control, args.instance);
let url = new URL(control.config.get("control.controller_url")!);
let instanceId = await lib.resolveInstance(ctl, args.instance);
let url = new URL(ctl.config.get("ctl.controller_url")!);
url.pathname += "api/upload-save";
url.searchParams.append("instance_id", String(instanceId));
url.searchParams.append("filename", filename);
@@ -341,7 +341,7 @@ instanceSaveCommands.add(new lib.Command({
body: (await fs.open(args.filepath)).createReadStream(),
duplex: "half",
headers: {
"X-Access-Token": control.config.get("control.controller_token")!,
"X-Access-Token": ctl.config.get("ctl.controller_token")!,
"Content-Type": "application/zip",
},
});
@@ -389,11 +389,11 @@ instanceSaveCommands.add(new lib.Command({
targetSave: string,
copy: boolean,
},
control: Control
ctl: Ctl
) {
let sourceInstanceId = await lib.resolveInstance(control, args.sourceInstance);
let targetInstanceId = await lib.resolveInstance(control, args.targetInstance);
let storedName = await control.send(
let sourceInstanceId = await lib.resolveInstance(ctl, args.sourceInstance);
let targetInstanceId = await lib.resolveInstance(ctl, args.targetInstance);
let storedName = await ctl.send(
new lib.InstanceTransferSaveRequest(
sourceInstanceId,
args.sourceSave,
@@ -411,11 +411,11 @@ instanceSaveCommands.add(new lib.Command({
yargs.positional("instance", { describe: "Instance to download save from", type: "string" });
yargs.positional("save", { describe: "Save to download", type: "string" });
}],
handler: async function(args: { instance: string, save: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
let streamId = await control.send(new lib.InstanceDownloadSaveRequest(instanceId, args.save));
handler: async function(args: { instance: string, save: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
let streamId = await ctl.send(new lib.InstanceDownloadSaveRequest(instanceId, args.save));
let url = new URL(control.config.get("control.controller_url")!);
let url = new URL(ctl.config.get("ctl.controller_url")!);
url.pathname += `api/stream/${streamId}`;
const filename = await lib.downloadFile(url, args.save, "rename");
@@ -428,9 +428,9 @@ instanceSaveCommands.add(new lib.Command({
yargs.positional("instance", { describe: "Instance to delete save from", type: "string" });
yargs.positional("save", { describe: "Save to delete", type: "string" });
}],
handler: async function(args: { instance: string, save: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.send(new lib.InstanceDeleteSaveRequest(instanceId, args.save));
handler: async function(args: { instance: string, save: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.send(new lib.InstanceDeleteSaveRequest(instanceId, args.save));
},
}));
instanceCommands.add(instanceSaveCommands);
@@ -439,10 +439,10 @@ instanceCommands.add(new lib.Command({
definition: ["export-data <instance>", "Export item icons and locale from instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to export from", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo({ instanceId }, new lib.InstanceExportDataRequest());
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo({ instanceId }, new lib.InstanceExportDataRequest());
},
}));
@@ -450,9 +450,9 @@ instanceCommands.add(new lib.Command({
definition: ["save-game <instance>", "Save the running game of an instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to save the game on", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.sendTo({ instanceId }, new lib.InstanceSaveGameRequest());
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.sendTo({ instanceId }, new lib.InstanceSaveGameRequest());
},
}));
@@ -460,10 +460,10 @@ instanceCommands.add(new lib.Command({
definition: ["extract-players <instance>", "Extract players from running save into the cluster.", (yargs) => {
yargs.positional("instance", { describe: "Instance to extract players and online time from", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo({ instanceId }, new lib.InstanceExtractPlayersRequest());
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo({ instanceId }, new lib.InstanceExtractPlayersRequest());
},
}));
@@ -475,11 +475,11 @@ instanceCommands.add(new lib.Command({
"keep-open": { describe: "Keep console open", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: { instance: string, save?: string, keepOpen: boolean }, control: Control) {
const instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo({ instanceId }, new lib.InstanceStartRequest(args.save));
control.keepOpen = args.keepOpen;
handler: async function(args: { instance: string, save?: string, keepOpen: boolean }, ctl: Ctl) {
const instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo({ instanceId }, new lib.InstanceStartRequest(args.save));
ctl.keepOpen = args.keepOpen;
},
}));
instanceCommands.add(new lib.Command({
@@ -490,11 +490,11 @@ instanceCommands.add(new lib.Command({
"keep-open": { describe: "Keep console open", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: { instance: string, save?: string, keepOpen: boolean }, control: Control) {
const instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo({ instanceId }, new lib.InstanceRestartRequest(args.save));
control.keepOpen = args.keepOpen;
handler: async function(args: { instance: string, save?: string, keepOpen: boolean }, ctl: Ctl) {
const instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo({ instanceId }, new lib.InstanceRestartRequest(args.save));
ctl.keepOpen = args.keepOpen;
},
}));
@@ -509,9 +509,9 @@ instanceCommands.add(new lib.Command({
},
});
}],
handler: async function(args: { force: boolean }, control: Control) {
handler: async function(args: { force: boolean }, ctl: Ctl) {
// Get all instances
const instances = await control.send(new lib.InstanceDetailsListRequest());
const instances = await ctl.send(new lib.InstanceDetailsListRequest());
// Filter instances that should be started
const instancesToStart = instances.filter((instance: lib.InstanceDetails) => {
@@ -541,7 +541,7 @@ instanceCommands.add(new lib.Command({
// Start all filtered instances
const startPromises = instancesToStart.map(async (instance: lib.InstanceDetails) => {
try {
await control.sendTo({ instanceId: instance.id }, new lib.InstanceStartRequest());
await ctl.sendTo({ instanceId: instance.id }, new lib.InstanceStartRequest());
print(`✓ Started ${instance.name}`);
} catch (error) {
print(`✗ Failed to start ${instance.name}: ${error}`);
@@ -575,15 +575,15 @@ instanceCommands.add(new lib.Command({
mapSettings?: string,
keepOpen: boolean,
},
control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
await control.sendTo(
await ctl.sendTo(
{ instanceId },
new lib.InstanceLoadScenarioRequest(args.scenario, seed, mapGenSettings, mapSettings),
);
control.keepOpen = args.keepOpen;
ctl.keepOpen = args.keepOpen;
},
}));
@@ -591,18 +591,18 @@ instanceCommands.add(new lib.Command({
definition: ["stop <instance>", "Stop instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to stop", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo({ instanceId }, new lib.InstanceStopRequest());
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo({ instanceId }, new lib.InstanceStopRequest());
},
}));
instanceCommands.add(new lib.Command({
definition: ["stop-all", "Stop all running instances", () => {}],
handler: async function(_args, control: Control) {
handler: async function(_args, ctl: Ctl) {
// Get all instances
const instances = await control.send(new lib.InstanceDetailsListRequest());
const instances = await ctl.send(new lib.InstanceDetailsListRequest());
// Filter instances that should be stopped
const instancesToStop = instances
@@ -621,7 +621,7 @@ instanceCommands.add(new lib.Command({
// Stop all filtered instances
const stopPromises = instancesToStop.map(async (instance: lib.InstanceDetails) => {
try {
await control.sendTo({ instanceId: instance.id }, new lib.InstanceStopRequest());
await ctl.sendTo({ instanceId: instance.id }, new lib.InstanceStopRequest());
print(`✓ Stopped ${instance.name}`);
} catch (error) {
print(`✗ Failed to stop ${instance.name}: ${error}`);
@@ -637,10 +637,10 @@ instanceCommands.add(new lib.Command({
definition: ["kill <instance>", "Kill instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to kill", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instanceIds: [instanceId] });
await control.sendTo({ instanceId }, new lib.InstanceKillRequest());
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.setLogSubscriptions({ instanceIds: [instanceId] });
await ctl.sendTo({ instanceId }, new lib.InstanceKillRequest());
},
}));
@@ -648,9 +648,9 @@ instanceCommands.add(new lib.Command({
definition: ["delete <instance>", "Delete instance", (yargs) => {
yargs.positional("instance", { describe: "Instance to delete", type: "string" });
}],
handler: async function(args: { instance: string }, control: Control) {
let instanceId = await lib.resolveInstance(control, args.instance);
await control.send(new lib.InstanceDeleteRequest(instanceId));
handler: async function(args: { instance: string }, ctl: Ctl) {
let instanceId = await lib.resolveInstance(ctl, args.instance);
await ctl.send(new lib.InstanceDeleteRequest(instanceId));
},
}));
@@ -659,9 +659,9 @@ instanceCommands.add(new lib.Command({
yargs.positional("instance", { describe: "Instance to send to", type: "string" });
yargs.positional("command", { describe: "command to send", type: "string" });
}],
handler: async function(args: { instance: string, command: string }, control: Control) {
let result = await control.sendTo(
{ instanceId: await lib.resolveInstance(control, args.instance) },
handler: async function(args: { instance: string, command: string }, ctl: Ctl) {
let result = await ctl.sendTo(
{ instanceId: await lib.resolveInstance(ctl, args.instance) },
new lib.InstanceSendRconRequest(args.command),
);
+10 -10
View File
@@ -2,7 +2,7 @@ import winston from "winston";
import * as lib from "@clusterio/lib";
import { ConsoleTransport, levels, logger } from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
export const logCommands = new lib.CommandTree({ name: "log", description: "Log inspection" });
logCommands.add(new lib.Command({
@@ -16,17 +16,17 @@ logCommands.add(new lib.Command({
}],
handler: async function(
args: { all: boolean, controller: boolean, host: string | null, instance: string | null },
control: Control
ctl: Ctl
) {
if (!args.all && !args.controller && !args.host && !args.instance) {
logger.error("At least one of --all, --controller, --host and --instance must be passed");
process.exitCode = 1;
return;
}
let instanceIds = args.instance ? [await lib.resolveInstance(control, args.instance)] : [];
let hostIds = args.host ? [await lib.resolveHost(control, args.host)] : [];
await control.setLogSubscriptions({ all: args.all, controller: args.controller, hostIds, instanceIds });
control.keepOpen = true;
let instanceIds = args.instance ? [await lib.resolveInstance(ctl, args.instance)] : [];
let hostIds = args.host ? [await lib.resolveHost(ctl, args.host)] : [];
await ctl.setLogSubscriptions({ all: args.all, controller: args.controller, hostIds, instanceIds });
ctl.keepOpen = true;
},
}));
@@ -52,16 +52,16 @@ logCommands.add(new lib.Command({
limit: number,
start: boolean,
},
control: Control
ctl: Ctl
) {
if (!args.all && !args.controller && !args.host && !args.instance) {
logger.error("At least one of --all, --controller, --host and --instance must be passed");
process.exitCode = 1;
return;
}
let instanceIds = args.instance ? [await lib.resolveInstance(control, args.instance)] : [];
let hostIds = args.host ? [await lib.resolveHost(control, args.host)] : [];
let result = await control.send(new lib.LogQueryRequest(
let instanceIds = args.instance ? [await lib.resolveInstance(ctl, args.instance)] : [];
let hostIds = args.host ? [await lib.resolveHost(ctl, args.host)] : [];
let result = await ctl.send(new lib.LogQueryRequest(
args.all,
args.controller,
hostIds,
+15 -15
View File
@@ -7,7 +7,7 @@ import util from "util";
import * as lib from "@clusterio/lib";
import { logger } from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
@@ -19,11 +19,11 @@ modCommands.add(new lib.Command({
yargs.positional("name", { describe: "Mod name to show details for", type: "string" });
yargs.positional("mod-version", { describe: "Version of the mod", type: "string" });
}],
handler: async function(args: { name: string, modVersion: string }, control: Control) {
handler: async function(args: { name: string, modVersion: string }, ctl: Ctl) {
if (!lib.isSourceVersion(args.modVersion)) {
throw new lib.CommandError("mod-version must match format digit.digit.digit");
}
let modInfo = await control.send(new lib.ModGetRequest(args.name, args.modVersion));
let modInfo = await ctl.send(new lib.ModGetRequest(args.name, args.modVersion));
for (let [field, value] of Object.entries(modInfo)) {
if (value instanceof Array) {
print(`${field}:`);
@@ -48,8 +48,8 @@ modCommands.add(new lib.Command({
},
});
}],
handler: async function(args: { fields: string[] }, control: Control) {
let mods = await control.send(new lib.ModListRequest());
handler: async function(args: { fields: string[] }, ctl: Ctl) {
let mods = await ctl.send(new lib.ModListRequest());
if (!args.fields.includes("all")) {
for (let entry of mods) {
for (let field of Object.keys(entry)) {
@@ -106,13 +106,13 @@ modCommands.add(new lib.Command({
sortOrder: "asc" | "desc",
fields: string[],
},
control: Control
ctl: Ctl
) {
const searchVersion = lib.normaliseSourceVersion(String(args.factorioVersion));
if (searchVersion === undefined) {
throw new Error(`Invalid factorio version "${args.factorioVersion}"`);
}
let response = await control.send(new lib.ModSearchRequest(
let response = await ctl.send(new lib.ModSearchRequest(
args.query,
lib.normaliseMajorMinorVersion(searchVersion),
args.page,
@@ -143,13 +143,13 @@ modCommands.add(new lib.Command({
definition: ["upload <file>", "Upload mod to the cluster", (yargs) => {
yargs.positional("file", { describe: "File to upload", type: "string" });
}],
handler: async function(args: { file: string }, control: Control) {
handler: async function(args: { file: string }, ctl: Ctl) {
let filename = path.basename(args.file);
if (!filename.endsWith(".zip")) {
throw new lib.CommandError("Mod filename must end with .zip");
}
let url = new URL(control.config.get("control.controller_url")!);
let url = new URL(ctl.config.get("ctl.controller_url")!);
url.pathname += "api/upload-mod";
url.searchParams.append("filename", filename);
@@ -158,7 +158,7 @@ modCommands.add(new lib.Command({
body: (await fs.open(args.file)).createReadStream(),
duplex: "half",
headers: {
"X-Access-Token": control.config.get("control.controller_token")!,
"X-Access-Token": ctl.config.get("ctl.controller_token")!,
"Content-Type": "application/zip",
},
});
@@ -190,13 +190,13 @@ modCommands.add(new lib.Command({
yargs.positional("name", { describe: "Internal name of mod to download", type: "string" });
yargs.positional("mod-version", { describe: "Version of mod to download", type: "string" });
}],
handler: async function(args: { name: string, modVersion: string }, control: Control) {
handler: async function(args: { name: string, modVersion: string }, ctl: Ctl) {
if (!lib.isSourceVersion(args.modVersion)) {
throw new lib.CommandError("mod-version must match format digit.digit.digit");
}
let streamId = await control.send(new lib.ModDownloadRequest(args.name, args.modVersion));
let streamId = await ctl.send(new lib.ModDownloadRequest(args.name, args.modVersion));
let url = new URL(control.config.get("control.controller_url")!);
let url = new URL(ctl.config.get("ctl.controller_url")!);
url.pathname += `api/stream/${streamId}`;
let filename = `${args.name}_${args.modVersion}.zip`;
await lib.downloadFile(url, filename, "overwrite");
@@ -210,10 +210,10 @@ modCommands.add(new lib.Command({
yargs.positional("name", { describe: "Name of mod to delete", type: "string" });
yargs.positional("mod-version", { describe: "Version of mod to delete", type: "string" });
}],
handler: async function(args: { name: string, modVersion: string }, control: Control) {
handler: async function(args: { name: string, modVersion: string }, ctl: Ctl) {
if (!lib.isSourceVersion(args.modVersion)) {
throw new lib.CommandError("mod-version must match format digit.digit.digit");
}
await control.send(new lib.ModDeleteRequest(args.name, args.modVersion));
await ctl.send(new lib.ModDeleteRequest(args.name, args.modVersion));
},
}));
+21 -21
View File
@@ -2,7 +2,7 @@ import asTableModule from "as-table";
import * as lib from "@clusterio/lib";
import { logger } from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
@@ -12,12 +12,12 @@ modPackCommands.add(new lib.Command({
definition: ["show <mod-pack>", "Show details of mod pack", (yargs) => {
yargs.positional("mod-pack", { describe: "Mod pack to show", type: "string" });
}],
handler: async function(args: { modPack: string }, control: Control) {
handler: async function(args: { modPack: string }, ctl: Ctl) {
let mods = new Map(
(await control.send(new lib.ModListRequest())).map(m => [m.id, m])
(await ctl.send(new lib.ModListRequest())).map(m => [m.id, m])
);
let modPack = await control.send(
new lib.ModPackGetRequest(await lib.resolveModPack(control, args.modPack))
let modPack = await ctl.send(
new lib.ModPackGetRequest(await lib.resolveModPack(ctl, args.modPack))
);
for (let [field, value] of Object.entries(modPack)) {
@@ -57,8 +57,8 @@ modPackCommands.add(new lib.Command({
modPackCommands.add(new lib.Command({
definition: [["list", "l"], "List mod packs in the cluster"],
handler: async function(args: object, control: Control) {
let modPacks = await control.send(new lib.ModPackListRequest());
handler: async function(args: object, ctl: Ctl) {
let modPacks = await ctl.send(new lib.ModPackListRequest());
let fields = ["id", "name", "factorioVersion"];
for (let entry of modPacks) {
for (let field of Object.keys(entry)) {
@@ -179,7 +179,7 @@ modPackCommands.add(new lib.Command({
stringSetting?: string[],
colorSetting?: string[],
},
control: Control,
ctl: Ctl,
) {
const modPack = new lib.ModPack();
modPack.name = args.name;
@@ -193,7 +193,7 @@ modPackCommands.add(new lib.Command({
setModPackMods(modPack, args.mods);
setModPackModsEnabled(modPack, args.disabledMods, false);
setModPackSettings(modPack, args);
await control.send(new lib.ModPackCreateRequest(modPack));
await ctl.send(new lib.ModPackCreateRequest(modPack));
print(`Created mod pack ${modPack.name} (${modPack.id})`);
},
}));
@@ -202,9 +202,9 @@ modPackCommands.add(new lib.Command({
definition: ["import <string>", "Import mod pack string", (yargs) => {
yargs.positional("string", { describe: "Mod pack string to import", type: "string" });
}],
handler: async function(args: { string: string }, control: Control) {
handler: async function(args: { string: string }, ctl: Ctl) {
const modPack = lib.ModPack.fromModPackString(args.string);
await control.send(new lib.ModPackCreateRequest(modPack));
await ctl.send(new lib.ModPackCreateRequest(modPack));
print(`Created mod pack ${modPack.name} (${modPack.id})`);
},
}));
@@ -213,9 +213,9 @@ modPackCommands.add(new lib.Command({
definition: ["export <mod-pack>", "Export mod pack string", (yargs) => {
yargs.positional("string", { describe: "Mod pack to export", type: "string" });
}],
handler: async function(args: { modPack: string }, control: Control) {
const modPack = await control.send(
new lib.ModPackGetRequest(await lib.resolveModPack(control, args.modPack))
handler: async function(args: { modPack: string }, ctl: Ctl) {
const modPack = await ctl.send(
new lib.ModPackGetRequest(await lib.resolveModPack(ctl, args.modPack))
);
print(modPack.toModPackString());
},
@@ -257,10 +257,10 @@ modPackCommands.add(new lib.Command({
colorSetting?: string[],
removeSetting?: string[],
},
control: Control,
ctl: Ctl,
) {
const modPack = await control.send(
new lib.ModPackGetRequest(await lib.resolveModPack(control, args.modPack))
const modPack = await ctl.send(
new lib.ModPackGetRequest(await lib.resolveModPack(ctl, args.modPack))
);
if (args.name) { modPack.name = args.name; }
@@ -300,7 +300,7 @@ modPackCommands.add(new lib.Command({
}
}
}
await control.send(new lib.ModPackUpdateRequest(modPack));
await ctl.send(new lib.ModPackUpdateRequest(modPack));
},
}));
@@ -308,8 +308,8 @@ modPackCommands.add(new lib.Command({
definition: ["delete <mod-pack>", "Delete mod pack", (yargs) => {
yargs.positional("mod-pack", { describe: "Mod pack to delete", type: "string" });
}],
handler: async function(args: { modPack: string }, control: Control) {
const id = await lib.resolveModPack(control, args.modPack);
await control.send(new lib.ModPackDeleteRequest(id));
handler: async function(args: { modPack: string }, ctl: Ctl) {
const id = await lib.resolveModPack(ctl, args.modPack);
await ctl.send(new lib.ModPackDeleteRequest(id));
},
}));
+3 -3
View File
@@ -1,7 +1,7 @@
import asTableModule from "as-table";
import * as lib from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
@@ -9,8 +9,8 @@ const asTable = asTableModule.configure({ delimiter: " | " });
export const permissionCommands = new lib.CommandTree({ name: "permission", description: "Permission inspection" });
permissionCommands.add(new lib.Command({
definition: [["list", "l"], "List permissions in the cluster"],
handler: async function(args: object, control: Control) {
let permissions = await control.send(new lib.PermissionListRequest());
handler: async function(args: object, ctl: Ctl) {
let permissions = await ctl.send(new lib.PermissionListRequest());
print(asTable(permissions));
},
}));
+12 -12
View File
@@ -2,7 +2,7 @@ import asTableModule from "as-table";
import * as lib from "@clusterio/lib";
import { logger } from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
@@ -10,8 +10,8 @@ const asTable = asTableModule.configure({ delimiter: " | " });
export const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" });
roleCommands.add(new lib.Command({
definition: [["list", "l"], "List roles in the cluster"],
handler: async function(args: object, control: Control) {
let roles = await control.send(new lib.RoleListRequest());
handler: async function(args: object, ctl: Ctl) {
let roles = await ctl.send(new lib.RoleListRequest());
print(asTable(roles));
},
}));
@@ -24,8 +24,8 @@ roleCommands.add(new lib.Command({
"permissions": { describe: "Permissions role grants", nargs: 1, array: true, type: "string", default: [] },
});
}],
handler: async function(args: { name: string, description: string, permissions: string[] }, control: Control) {
let id = await control.send(new lib.RoleCreateRequest(
handler: async function(args: { name: string, description: string, permissions: string[] }, ctl: Ctl) {
let id = await ctl.send(new lib.RoleCreateRequest(
args.name,
args.description,
args.permissions,
@@ -58,9 +58,9 @@ roleCommands.add(new lib.Command({
removePerms?: string[],
grantDefault?: boolean,
},
control: Control
ctl: Ctl
) {
let role = await lib.retrieveRole(control, args.role);
let role = await lib.retrieveRole(ctl, args.role);
if (args.name !== undefined) {
role.name = args.name;
@@ -81,10 +81,10 @@ roleCommands.add(new lib.Command({
if (args.setPerms !== undefined) {
role.permissions = new Set(args.setPerms);
}
await control.send(new lib.RoleUpdateRequest(role.id, role.name, role.description, [...role.permissions]));
await ctl.send(new lib.RoleUpdateRequest(role.id, role.name, role.description, [...role.permissions]));
if (args.grantDefault) {
await control.send(new lib.RoleGrantDefaultPermissionsRequest(role.id));
await ctl.send(new lib.RoleGrantDefaultPermissionsRequest(role.id));
}
},
}));
@@ -93,8 +93,8 @@ roleCommands.add(new lib.Command({
definition: ["delete <role>", "Delete role", (yargs) => {
yargs.positional("role", { describe: "Role to delete", type: "string" });
}],
handler: async function(args: { role: string }, control: Control) {
let role = await lib.retrieveRole(control, args.role);
await control.send(new lib.RoleDeleteRequest(role.id));
handler: async function(args: { role: string }, ctl: Ctl) {
let role = await lib.retrieveRole(ctl, args.role);
await ctl.send(new lib.RoleDeleteRequest(role.id));
},
}));
+29 -29
View File
@@ -3,7 +3,7 @@ import asTableModule from "as-table";
import path from "path";
import * as lib from "@clusterio/lib";
import type { Control } from "../ctl.js";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
@@ -16,8 +16,8 @@ userCommands.add(new lib.Command({
"instance-stats": { describe: "include per-instance stats", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: { name: string, instanceStats: boolean }, control: Control) {
let user = await control.send(new lib.UserGetRequest(args.name));
handler: async function(args: { name: string, instanceStats: boolean }, ctl: Ctl) {
let user = await ctl.send(new lib.UserGetRequest(args.name));
Object.assign(user, user.playerStats);
// @ts-expect-error Terrible hack
delete user.playerStats;
@@ -27,7 +27,7 @@ userCommands.add(new lib.Command({
print(asTable(Object.entries(user).map(([property, value]) => ({ property, value }))));
if (args.instanceStats) {
let instances = await control.send(new lib.InstanceDetailsListRequest());
let instances = await ctl.send(new lib.InstanceDetailsListRequest());
function instanceName(id: number) {
let instance = instances.find(i => i.id === id);
if (instance) {
@@ -51,8 +51,8 @@ userCommands.add(new lib.Command({
"attributes": { describe: "include admin/whitelisted/banned", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: { stats: boolean, attributes: boolean }, control: Control) {
let users = await control.send(new lib.UserListRequest());
handler: async function(args: { stats: boolean, attributes: boolean }, ctl: Ctl) {
let users = await ctl.send(new lib.UserListRequest());
for (let user of users) {
if (args.stats) {
Object.assign(user, user.playerStats);
@@ -82,8 +82,8 @@ userCommands.add(new lib.Command({
definition: ["create <name>", "Create a user", (yargs) => {
yargs.positional("name", { describe: "Name of user to create", type: "string" });
}],
handler: async function(args: { name: string }, control: Control) {
await control.send(new lib.UserCreateRequest(args.name));
handler: async function(args: { name: string }, ctl: Ctl) {
await ctl.send(new lib.UserCreateRequest(args.name));
},
}));
@@ -91,8 +91,8 @@ userCommands.add(new lib.Command({
definition: ["revoke-token <name>", "Revoke token for user", (yargs) => {
yargs.positional("name", { describe: "Name of user to revoke token for", type: "string" });
}],
handler: async function(args: { name: string }, control: Control) {
await control.send(new lib.UserRevokeTokenRequest(args.name));
handler: async function(args: { name: string }, ctl: Ctl) {
await ctl.send(new lib.UserRevokeTokenRequest(args.name));
},
}));
@@ -104,8 +104,8 @@ userCommands.add(new lib.Command({
"create": { describe: "Create user if it does not exist", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: { user: string, revoke: boolean, create: boolean }, control: Control) {
await control.send(new lib.UserSetAdminRequest(args.user, args.create, !args.revoke));
handler: async function(args: { user: string, revoke: boolean, create: boolean }, ctl: Ctl) {
await ctl.send(new lib.UserSetAdminRequest(args.user, args.create, !args.revoke));
},
}));
@@ -117,8 +117,8 @@ userCommands.add(new lib.Command({
"create": { describe: "Create user if it does not exist", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: { user: string, remove: boolean, create: boolean }, control: Control) {
await control.send(new lib.UserSetWhitelistedRequest(args.user, args.create, !args.remove));
handler: async function(args: { user: string, remove: boolean, create: boolean }, ctl: Ctl) {
await ctl.send(new lib.UserSetWhitelistedRequest(args.user, args.create, !args.remove));
},
}));
@@ -138,9 +138,9 @@ userCommands.add(new lib.Command({
reason: string,
create: boolean
},
control: Control
ctl: Ctl
) {
await control.send(new lib.UserSetBannedRequest(args.user, args.create, !args.pardon, args.reason));
await ctl.send(new lib.UserSetBannedRequest(args.user, args.create, !args.pardon, args.reason));
},
}));
@@ -149,8 +149,8 @@ userCommands.add(new lib.Command({
yargs.positional("user", { describe: "Name of user to change roles for", type: "string" });
yargs.positional("roles", { describe: "roles to assign", type: "string" });
}],
handler: async function(args: { user: string, roles: string[] }, control: Control) {
let roles = await control.send(new lib.RoleListRequest());
handler: async function(args: { user: string, roles: string[] }, ctl: Ctl) {
let roles = await ctl.send(new lib.RoleListRequest());
let resolvedRoles = [];
for (let roleName of args.roles) {
@@ -174,7 +174,7 @@ userCommands.add(new lib.Command({
}
}
await control.send(new lib.UserUpdateRolesRequest(args.user, resolvedRoles));
await ctl.send(new lib.UserUpdateRolesRequest(args.user, resolvedRoles));
},
}));
@@ -182,8 +182,8 @@ userCommands.add(new lib.Command({
definition: ["delete <user>", "Delete user", (yargs) => {
yargs.positional("user", { describe: "Name of user to delete", type: "string" });
}],
handler: async function(args: { user: string }, control: Control) {
await control.send(new lib.UserDeleteRequest(args.user));
handler: async function(args: { user: string }, ctl: Ctl) {
await ctl.send(new lib.UserDeleteRequest(args.user));
},
}));
@@ -194,7 +194,7 @@ async function handleImportOrRestore(args: {
admins: boolean,
whitelist: boolean,
noBackup?: boolean,
}, control: Control, restore: boolean) {
}, ctl: Ctl, restore: boolean) {
let importType: ConstructorParameters<typeof lib.UserBulkImportRequest>[0];
const data = JSON.parse((await fs.readFile(args.filepath)).toString());
const optionCount = [args.users, args.bans, args.admins, args.whitelist]
@@ -218,7 +218,7 @@ async function handleImportOrRestore(args: {
throw new lib.CommandError("Unknown json file, please specify an option");
}
const backup = await control.send(
const backup = await ctl.send(
new lib.UserBulkImportRequest(importType, importType === "users" ? data.users : data, restore)
);
@@ -239,8 +239,8 @@ userCommands.add(new lib.Command({
"whitelist": { describe: "Import whitelist json", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: any, control: any) {
await handleImportOrRestore(args, control, false);
handler: async function(args: any, ctl: any) {
await handleImportOrRestore(args, ctl, false);
},
}));
@@ -255,8 +255,8 @@ userCommands.add(new lib.Command({
"no-backup": { describe: "Don't save a backup to the cwd", nargs: 0, type: "boolean", default: false },
});
}],
handler: async function(args: any, control: any) {
await handleImportOrRestore(args, control, true);
handler: async function(args: any, ctl: any) {
await handleImportOrRestore(args, ctl, true);
},
}));
@@ -276,7 +276,7 @@ userCommands.add(new lib.Command({
bans: boolean,
admins: boolean,
whitelist: boolean,
}, control: Control) {
}, ctl: Ctl) {
let exportType = "users" as ConstructorParameters<typeof lib.UserBulkExportRequest>[0];
const optionCount = [args.bans, args.admins, args.whitelist]
.reduce((acc, bool) => (bool ? acc + 1 : acc), 0);
@@ -296,7 +296,7 @@ userCommands.add(new lib.Command({
exportType = "whitelist";
}
await fs.writeFile(args.filepath, JSON.stringify(await control.send(
await fs.writeFile(args.filepath, JSON.stringify(await ctl.send(
new lib.UserBulkExportRequest(exportType)
), undefined, "\t"));
print(`Exported ${exportType} to ${args.filepath}`);