mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
* Improve config, message, and module templates * Update global handler in template module * Add comments to empty instance template
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { BaseCtlPlugin, type Control } from "@clusterio/ctl";
|
|
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";
|
|
/* 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: { foo: string }, control: 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 class CtlPlugin extends BaseCtlPlugin {
|
|
async addCommands(rootCommand: CommandTree) {
|
|
rootCommand.add(pluginCommands);
|
|
}
|
|
}
|