mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 15:24:52 +09:00
Replace invokeHook and the per plugin on* methods with AsyncHook collections on the controller, host, instance, clusterioctl and web control objects. Plugin entrypoints export a default function that receives a load context and attaches handlers to the hooks it needs. Class exports still load through fromContext with a deprecation warning. The create templates and docs use the entrypoint function. This is clusterio/clusterio#921 recreated on top of master after the ESM migration and the PluginDeclaration permissions change. Closes #730 Co-Authored-By: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import type { Argv } from "yargs";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
import { controllerCommands } from "./commands_controller.js";
|
|
import { hostCommands } from "./commands_host.js";
|
|
import { instanceCommands } from "./commands_instance.js";
|
|
import { modPackCommands } from "./commands_mod_pack.js";
|
|
import { modCommands } from "./commands_mod.js";
|
|
import { permissionCommands } from "./commands_permission.js";
|
|
import { roleCommands } from "./commands_role.js";
|
|
import { userCommands } from "./commands_user.js";
|
|
import { logCommands } from "./commands_log.js";
|
|
import { debugCommands } from "./commands_debug.js";
|
|
import type { CtlHooks } from "./BaseCtlPlugin.js";
|
|
|
|
export async function registerCommands(ctlHooks: CtlHooks, yargs: Argv) {
|
|
const rootCommands = new lib.CommandTree({ name: "clusterioctl", description: "Manage cluster" });
|
|
rootCommands.add(controllerCommands);
|
|
rootCommands.add(hostCommands);
|
|
rootCommands.add(instanceCommands);
|
|
rootCommands.add(modPackCommands);
|
|
rootCommands.add(modCommands);
|
|
rootCommands.add(permissionCommands);
|
|
rootCommands.add(roleCommands);
|
|
rootCommands.add(userCommands);
|
|
rootCommands.add(logCommands);
|
|
rootCommands.add(debugCommands);
|
|
|
|
await ctlHooks.addCommands.invoke(rootCommands);
|
|
|
|
for (let [name, command] of rootCommands.subCommands) {
|
|
if (name === command.name) {
|
|
command.register(yargs);
|
|
}
|
|
}
|
|
|
|
return rootCommands;
|
|
}
|