mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04: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>
27 lines
1018 B
JavaScript
27 lines
1018 B
JavaScript
import { CommandTree, Command } from "@clusterio/lib";
|
|
//%// We do not check for multi context here because it doesn't make sense to have a ctl without messages
|
|
import { PluginExampleEvent, PluginExampleRequest } from "./messages.js";
|
|
/* eslint-disable no-console */
|
|
|
|
const pluginCommands = new CommandTree({
|
|
name: "__plugin_name__", description: "The default description I forgot to change",
|
|
});
|
|
|
|
pluginCommands.add(new Command({
|
|
definition: ["my-command <foo>", "My command description that I really should change", (yargs) => {
|
|
yargs.positional("foo", { describe: "foo is foo!", type: "string" });
|
|
}],
|
|
handler: async function(args, control) {
|
|
const response = await control.sendTo("controller", new PluginExampleRequest(args.foo, [1, 2, 3]));
|
|
console.log(response);
|
|
console.log(args);
|
|
},
|
|
}));
|
|
|
|
/* eslint-enable no-console */
|
|
export default async function loadCtlPlugin(context) {
|
|
context.hooks.addCommands.attach(context.plugin.name, async (rootCommand) => {
|
|
rootCommand.add(pluginCommands);
|
|
});
|
|
}
|