mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Reworked to use throw error, added system for getting config groups
Now using `throw error` to exit out, instead of exit(1). Reworked config get system to use the map of configs in libConfig.MasterConfig.groups .
This commit is contained in:
1 parent
77e9b929dc
commit
08a8182173
1 file changed
+13
-10
+13
-10
@@ -106,7 +106,6 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
await libLink.messages.setMasterConfigProp.send(control, request);
|
await libLink.messages.setMasterConfigProp.send(control, request);
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
masterConfigCommands.add(new libCommand.Command({
|
masterConfigCommands.add(new libCommand.Command({
|
||||||
definition: ["edit [editor]", "Edit master configuration", (yargs) => {
|
definition: ["edit [editor]", "Edit master configuration", (yargs) => {
|
||||||
yargs.positional("editor", { describe: "Editor to use",
|
yargs.positional("editor", { describe: "Editor to use",
|
||||||
@@ -127,33 +126,37 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
/* eslint-enable */
|
/* 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
|
||||||
} else {
|
} else {
|
||||||
print("No editor avalible to use. Checked CLI input, EDITOR env var and VISUAL env var");
|
print();
|
||||||
exit(1); // TODO: exit gracefully apon no editor
|
throw new libErrors.CommandError("No editor avalible. Checked CLI input, EDITOR and VISUAL env vars");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function afterEditorDone() {
|
async function afterEditorDone() {
|
||||||
print(JSON.stringify(response.serialized_config));
|
let MainConfig = new libConfig.MasterConfig("exampleonetwothree123");
|
||||||
let masterConfig = new libConfig.MasterConfig("control");
|
await MainConfig.load(response.serialized_config, "exampleonetwothree123");
|
||||||
await masterConfig.load(response.serialized_config);
|
let groups = Array.from(libConfig.MasterConfig.groups.keys());
|
||||||
await masterConfig.init();
|
// convert from MapIterator to array
|
||||||
print(JSON.stringify(libConfig.MasterConfig.groups));
|
let mainConfigGroups = [];
|
||||||
|
for (let i = 0; i < groups.length; i++) {
|
||||||
|
mainConfigGroups[i] = MainConfig.group(groups[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <-- start process of running editor -->
|
// <-- start process of running editor -->
|
||||||
let editorSpawn = child_process.spawn(editor, [tmpFile], {
|
let editorSpawn = child_process.spawn(editor, [tmpFile], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
detached: true,
|
detached: true,
|
||||||
}); // TODO: Exit gracefully if editor not found
|
});
|
||||||
editorSpawn.on("data", (data) => {
|
editorSpawn.on("data", (data) => {
|
||||||
process.stdout.pipe(data);
|
process.stdout.pipe(data);
|
||||||
});
|
});
|
||||||
editorSpawn.on("err", (err) => {
|
editorSpawn.on("err", (err) => {
|
||||||
print(err);
|
print(err);
|
||||||
exit(1); // TODO: exit gracefully apon error from editor
|
throw new libErrors.CommandError("Editor throwed error.");
|
||||||
});
|
});
|
||||||
editorSpawn.on("exit", (exit) => {
|
editorSpawn.on("exit", (exit) => {
|
||||||
afterEditorDone();
|
afterEditorDone();
|
||||||
});
|
});
|
||||||
|
// this is more verbose then it probably needs to be, but IMO this is more readable
|
||||||
// <-- end process of starting editor -->
|
// <-- end process of starting editor -->
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in new issue
Block a user