mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Rename bases to templates and add per property inheritance
Review changes for #1142: - base becomes template everywhere (is_template, template_id, --template, --is-template, --templates, InstanceDetails.isTemplate). - Object fields inherit per property. inherited_fields lists the overridden properties for object fields and the template object is merged with them. - Linking a template also inherits fields that hold the default value. The server name stays per instance. - Ports are never inherited. - InstanceDetails carries templateId. Web UI: inherited values are locked until unlocked, overridden values can be inherited again, templates are listed separately, the create modal can create templates and instances from templates, and the instance page has "Create template" which can link the source. Part of #200 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01cf789f5d
commit
b5c372f109
21 files changed
+865
-312
No files matched your search
@@ -22,12 +22,12 @@ export const instanceCommands = new lib.CommandTree({
|
||||
instanceCommands.add(new lib.Command({
|
||||
definition: [["list", "l"], "List instances known to the controller", (yargs) => {
|
||||
yargs.options({
|
||||
"bases": { describe: "Include base instances", nargs: 0, type: "boolean", default: false },
|
||||
"templates": { describe: "Include templates", nargs: 0, type: "boolean", default: false },
|
||||
});
|
||||
}],
|
||||
handler: async function(args: { bases: boolean }, ctl: Ctl) {
|
||||
handler: async function(args: { templates: boolean }, ctl: Ctl) {
|
||||
let list = await ctl.send(new lib.InstanceDetailsListRequest());
|
||||
print(asTable(list.filter(instance => args.bases || !instance.isBase)));
|
||||
print(asTable(list.filter(instance => args.templates || !instance.isTemplate)));
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -38,12 +38,12 @@ instanceCommands.add(new lib.Command({
|
||||
yargs.options({
|
||||
"id": { type: "number", nargs: 1, describe: "Instance id" },
|
||||
"from": { type: "number", nargs: 1, describe: "Clone config from instance id" },
|
||||
"base": { type: "string", nargs: 1, describe: "Base instance to inherit config from" },
|
||||
"is-base": { type: "boolean", nargs: 0, describe: "Create the instance as a base" },
|
||||
"template": { type: "string", nargs: 1, describe: "Template to inherit config from" },
|
||||
"is-template": { type: "boolean", nargs: 0, describe: "Create the instance as a template" },
|
||||
});
|
||||
}],
|
||||
handler: async function(
|
||||
args: { name: string, id?: number, from?: number, base?: string, isBase?: boolean },
|
||||
args: { name: string, id?: number, from?: number, template?: string, isTemplate?: boolean },
|
||||
ctl: Ctl,
|
||||
) {
|
||||
let instanceConfig = new lib.InstanceConfig("control");
|
||||
@@ -52,13 +52,13 @@ instanceCommands.add(new lib.Command({
|
||||
instanceConfig.set("instance.id", args.id);
|
||||
}
|
||||
instanceConfig.set("instance.name", args.name);
|
||||
if (args.base !== undefined) {
|
||||
instanceConfig.set("instance.base_id", await lib.resolveInstance(ctl, args.base));
|
||||
fields.push("instance.base_id");
|
||||
if (args.template !== undefined) {
|
||||
instanceConfig.set("instance.template_id", await lib.resolveInstance(ctl, args.template));
|
||||
fields.push("instance.template_id");
|
||||
}
|
||||
if (args.isBase) {
|
||||
instanceConfig.set("instance.is_base", true);
|
||||
fields.push("instance.is_base");
|
||||
if (args.isTemplate) {
|
||||
instanceConfig.set("instance.is_template", true);
|
||||
fields.push("instance.is_template");
|
||||
}
|
||||
await ctl.send(new lib.InstanceCreateRequest(
|
||||
instanceConfig.toRemote("controller", fields),
|
||||
@@ -77,27 +77,39 @@ instanceConfigCommands.add(new lib.Command({
|
||||
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));
|
||||
const inherited = config["instance.base_id"] !== null
|
||||
? config["instance.inherited_fields"] as Record<string, true> ?? {}
|
||||
const inherited = config["instance.template_id"] !== null
|
||||
? config["instance.inherited_fields"] as Record<string, true | string[]> ?? {}
|
||||
: {};
|
||||
|
||||
for (let [name, value] of Object.entries(config)) {
|
||||
if (name === "instance.inherited_fields") {
|
||||
continue;
|
||||
}
|
||||
print(`${name} ${JSON.stringify(value)}${inherited[name] ? " (inherited)" : ""}`);
|
||||
const entry = inherited[name];
|
||||
let note = "";
|
||||
if (entry instanceof Array && entry.length) {
|
||||
note = ` (inherited except ${entry.join(", ")})`;
|
||||
} else if (entry) {
|
||||
note = " (inherited)";
|
||||
}
|
||||
print(`${name} ${JSON.stringify(value)}${note}`);
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
instanceConfigCommands.add(new lib.Command({
|
||||
definition: ["inherit <instance> <field>", "Make field in instance config use the value of its base", (yargs) => {
|
||||
yargs.positional("instance", { describe: "Instance to update config on", type: "string" });
|
||||
yargs.positional("field", { describe: "Field to inherit", type: "string" });
|
||||
}],
|
||||
handler: async function(args: { instance: string, field: string }, ctl: Ctl) {
|
||||
definition: [
|
||||
"inherit <instance> <field> [prop]",
|
||||
"Make field or property in instance config use the value of its template",
|
||||
(yargs) => {
|
||||
yargs.positional("instance", { describe: "Instance to update config on", type: "string" });
|
||||
yargs.positional("field", { describe: "Field to inherit", type: "string" });
|
||||
yargs.positional("prop", { describe: "Property of object field to inherit", type: "string" });
|
||||
},
|
||||
],
|
||||
handler: async function(args: { instance: string, field: string, prop?: string }, ctl: Ctl) {
|
||||
let instanceId = await lib.resolveInstance(ctl, args.instance);
|
||||
await ctl.send(new lib.InstanceConfigInheritFieldRequest(instanceId, args.field));
|
||||
await ctl.send(new lib.InstanceConfigInheritFieldRequest(instanceId, args.field, args.prop));
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -205,7 +217,7 @@ instanceConfigCommands.add(new lib.Command({
|
||||
const final = await configToKeyVal(data);
|
||||
const original = await configToKeyVal(allConfigElements);
|
||||
for (let index in final) {
|
||||
// Unchanged fields are skipped so they keep inheriting from the base
|
||||
// Unchanged fields are skipped so they keep inheriting from the template
|
||||
if (index in final && final[index] !== original[index]) {
|
||||
try {
|
||||
await ctl.send(new lib.InstanceConfigSetFieldRequest(
|
||||
|
||||
Reference in new issue
Block a user