mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Readded config file editing, working on config file value setting
This commit is contained in:
1 parent
6013fcd528
commit
bcc25047f2
1 file changed
+41
-1
+41
-1
@@ -142,15 +142,55 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
allConfigElements += `# ${desc}\n`;
|
allConfigElements += `# ${desc}\n`;
|
||||||
// split onto two lines for readability and es-lint
|
// split onto two lines for readability and es-lint
|
||||||
|
|
||||||
allConfigElements += `${group.name}.${name} ${value}\n\n`;
|
allConfigElements += `${group.name}.${name} = ${value}\n\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// use same method as master config list to grab values, with a small modification to add quotes around strings
|
// use same method as master config list to grab values, with a small modification to add quotes around strings
|
||||||
|
// this could be shorter but the lines would have to be very long, so imo this is better for readability
|
||||||
fs.writeFile(tmpFile, allConfigElements, (err) => {
|
fs.writeFile(tmpFile, allConfigElements, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let editorSpawn = child_process.spawn(editor, [tmpFile], {
|
||||||
|
stdio: "inherit",
|
||||||
|
detached: false,
|
||||||
|
});
|
||||||
|
editorSpawn.on("data", (data) => {
|
||||||
|
process.stdout.pipe(data);
|
||||||
|
});
|
||||||
|
function readTmpFile(c2) {
|
||||||
|
fs.readFile(tmpFile, "utf8", (err, data) => {
|
||||||
|
if (err) { throw err; }
|
||||||
|
let splitData = data.split(/\r?\n/);
|
||||||
|
// split on newlines
|
||||||
|
let filtered = splitData.filter((value) => !(value[0] === "#")).filter((a) => a);
|
||||||
|
// the last filter removes empty elements left by the first. Not done on one line due to readability.
|
||||||
|
let final = [];
|
||||||
|
for (let index in filtered) {
|
||||||
|
if (index in filtered) {
|
||||||
|
filtered[index] = filtered[index].split("=");
|
||||||
|
// split on the = we added eariler
|
||||||
|
filtered[index][1] = filtered[index][1].replace(/['"]+/g, "");
|
||||||
|
// remove quotes we added eariler
|
||||||
|
final[filtered[index][0].trim()] = filtered[index][1].trim();
|
||||||
|
// trim whitespace and put in final array for processing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let element in final) {
|
||||||
|
if (element in final) {
|
||||||
|
libLink.messages.setMasterConfigField.send(control, {
|
||||||
|
field: element,
|
||||||
|
value: final[element],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
editorSpawn.once("exit", (exit) => {
|
||||||
|
print("once");
|
||||||
|
readTmpFile(control);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user