Add notes to hosts, instances, users and other resources (#1000)

This commit is contained in:
Bastiaan authored and GitHub committed 2026-10-18 20:06:15 +03:00
1 parent ee39945c83
commit cbf2b10782
25 files changed
+830 -52

No files matched your search

+2
View File
@@ -8,6 +8,7 @@ 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 { noteCommands } from "./commands_note.js";
import { userCommands } from "./commands_user.js";
import { logCommands } from "./commands_log.js";
import { debugCommands } from "./commands_debug.js";
@@ -22,6 +23,7 @@ export async function registerCommands(ctlHooks: CtlHooks, yargs: Argv) {
rootCommands.add(modCommands);
rootCommands.add(permissionCommands);
rootCommands.add(roleCommands);
rootCommands.add(noteCommands);
rootCommands.add(userCommands);
rootCommands.add(logCommands);
rootCommands.add(debugCommands);
+72
View File
@@ -0,0 +1,72 @@
import asTableModule from "as-table";
import * as lib from "@clusterio/lib";
import type { Ctl } from "../ctl.js";
import { print } from "./command_ops.js";
const asTable = asTableModule.configure({ delimiter: " | " });
export const noteCommands = new lib.CommandTree({
name: "note", description: "Notes attached to hosts, instances, users and other resources",
});
noteCommands.add(new lib.Command({
definition: [["list", "l"], "List notes in the cluster", (yargs) => {
yargs.options({
"type": { describe: "Only list notes for this resource type", nargs: 1, type: "string" },
});
}],
handler: async function(args: { type?: string }, ctl: Ctl) {
let notes = await ctl.send(new lib.NoteListRequest());
if (args.type !== undefined) {
notes = notes.filter(note => note.resourceType === args.type);
}
print(asTable(notes.map(note => ({
type: note.resourceType,
id: note.resourceId,
updatedBy: note.updatedBy,
content: note.content,
}))));
},
}));
noteCommands.add(new lib.Command({
definition: ["get <type> <id>", "Show the note of a resource", (yargs) => {
yargs.positional("type", {
describe: "Resource type, one of host, instance, user, role, mod_pack, mod, save", type: "string",
});
yargs.positional("id", { describe: "Id of the resource", type: "string" });
}],
handler: async function(args: { type: string, id: string }, ctl: Ctl) {
const notes = await ctl.send(new lib.NoteListRequest());
const note = notes.find(n => n.resourceType === args.type && n.resourceId === args.id);
if (!note) {
throw new lib.CommandError(`No note for ${args.type} ${args.id}`);
}
print(note.content);
},
}));
noteCommands.add(new lib.Command({
definition: ["set <type> <id> <content>", "Set the note of a resource", (yargs) => {
yargs.positional("type", {
describe: "Resource type, one of host, instance, user, role, mod_pack, mod, save", type: "string",
});
yargs.positional("id", { describe: "Id of the resource", type: "string" });
yargs.positional("content", { describe: "Text of the note", type: "string" });
}],
handler: async function(args: { type: string, id: string, content: string }, ctl: Ctl) {
await ctl.send(new lib.NoteSetRequest(args.type, args.id, args.content));
},
}));
noteCommands.add(new lib.Command({
definition: ["delete <type> <id>", "Remove the note of a resource", (yargs) => {
yargs.positional("type", {
describe: "Resource type, one of host, instance, user, role, mod_pack, mod, save", type: "string",
});
yargs.positional("id", { describe: "Id of the resource", type: "string" });
}],
handler: async function(args: { type: string, id: string }, ctl: Ctl) {
await ctl.send(new lib.NoteSetRequest(args.type, args.id, ""));
},
}));