mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Refactored serializedConfigToString into function
I'm unable to test right now, so this is currently not yet tested. Will test asap.
This commit is contained in:
1 file changed
+27
-40
+27
-40
@@ -37,11 +37,10 @@ function print(...content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getEditor(argsEditor) {
|
async function getEditor(argsEditor) {
|
||||||
/* eslint-disable */
|
// eslint-disable-next-line
|
||||||
return argsEditor || process.ENV.EDITOR || process.env.VISUAL || -1
|
return argsEditor || process.ENV.EDITOR || process.env.VISUAL || -1
|
||||||
/* eslint-enable */
|
|
||||||
// needed for the process.env statements to not be flagged by eslint
|
// needed for the process.env statements to not be flagged by eslint
|
||||||
// prio for editors is CLI arg > env.EDITOR > env.VISUAL
|
// priority for editors is CLI argument > env.EDITOR > env.VISUAL
|
||||||
}
|
}
|
||||||
|
|
||||||
async function configToKeyVal(data) {
|
async function configToKeyVal(data) {
|
||||||
@@ -69,6 +68,29 @@ async function configToKeyVal(data) {
|
|||||||
return final;
|
return final;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function serializedConfigToString(serlializedConfig, configGroup, disallowedList) {
|
||||||
|
let allConfigElements = "";
|
||||||
|
for (let group of serializedConfig.groups) {
|
||||||
|
for (let [name, value] of Object.entries(group.fields)) {
|
||||||
|
if (`${group.name}.${name}` in disallowedList) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let desc = "";
|
||||||
|
try {
|
||||||
|
desc += configGroup.groups.get(group.name)._definitions.get(name).description;
|
||||||
|
} catch (err) {
|
||||||
|
desc += "No description found";
|
||||||
|
}
|
||||||
|
// split onto two lines for readability and es-lint
|
||||||
|
if (String(value) === "null") {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
allConfigElements += `${group.name}.${name} = ${value}\n\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allConfigElements;
|
||||||
|
}
|
||||||
|
|
||||||
const masterCommands = new libCommand.CommandTree({ name: "master", description: "Master management" });
|
const masterCommands = new libCommand.CommandTree({ name: "master", description: "Master management" });
|
||||||
const masterConfigCommands = new libCommand.CommandTree({
|
const masterConfigCommands = new libCommand.CommandTree({
|
||||||
name: "config", alias: ["c"], description: "master config management",
|
name: "config", alias: ["c"], description: "master config management",
|
||||||
@@ -154,23 +176,7 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
throw new libErrors.CommandError(`No editor avalible. Checked CLI input, EDITOR and VISUAL env vars
|
throw new libErrors.CommandError(`No editor avalible. Checked CLI input, EDITOR and VISUAL env vars
|
||||||
Try "ctl master config edit <editor of choice>"`);
|
Try "ctl master config edit <editor of choice>"`);
|
||||||
}
|
}
|
||||||
let allConfigElements = "";
|
let allConfigElements = await serializedConfigToString(respose.serialized_config, libConfig.MasterConfig, {});
|
||||||
for (let group of response.serialized_config.groups) {
|
|
||||||
for (let [name, value] of Object.entries(group.fields)) {
|
|
||||||
let desc = "";
|
|
||||||
try {
|
|
||||||
desc += libConfig.MasterConfig.groups.get(group.name)._definitions.get(name).description;
|
|
||||||
} catch (err) {
|
|
||||||
desc += "No description found";
|
|
||||||
}
|
|
||||||
// split onto two lines for readability and es-lint
|
|
||||||
if (String(value) === "null") {
|
|
||||||
value = "";
|
|
||||||
}
|
|
||||||
allConfigElements += `${group.name}.${name} = ${value}\n\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// this could be shorter but the lines would have to be very long, so imo this is better for readability
|
|
||||||
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@@ -431,26 +437,7 @@ instanceConfigCommands.add(new libCommand.Command({
|
|||||||
}
|
}
|
||||||
let allConfigElements = "";
|
let allConfigElements = "";
|
||||||
let disallowedList = {"instance.id": 0, "instance.assigned_slave": 0, "factorio.settings": 0};
|
let disallowedList = {"instance.id": 0, "instance.assigned_slave": 0, "factorio.settings": 0};
|
||||||
for (let group of response.serialized_config.groups) {
|
let allConfigElements = await serializedConfigToString(respose.serialized_config, libConfig.InstanceConfig, disallowedList);
|
||||||
for (let [name, value] of Object.entries(group.fields)) {
|
|
||||||
if (`${group.name}.${name}` in disallowedList) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let desc = "";
|
|
||||||
try {
|
|
||||||
desc += libConfig.InstanceConfig.groups.get(group.name)._definitions.get(name).description;
|
|
||||||
} catch (err) {
|
|
||||||
desc += "No description found";
|
|
||||||
}
|
|
||||||
allConfigElements += `# ${desc}\n`;
|
|
||||||
// split onto two lines for readability and es-lint
|
|
||||||
if (String(value) === "null") {
|
|
||||||
value = "";
|
|
||||||
}
|
|
||||||
allConfigElements += `${group.name}.${name} = ${value}\n\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// this could be shorter but the lines would have to be very long, so imo this is better for readability
|
|
||||||
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
await fs.writeFile(tmpFile, allConfigElements, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
Reference in new issue
Block a user