mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Refactored editor selection to function
This commit is contained in:
1 parent
e825f643e2
commit
6d5d9ced47
1 file changed
+23
-27
+23
-27
@@ -36,6 +36,24 @@ function print(...content) {
|
|||||||
console.log(...content);
|
console.log(...content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getEditor(argsEditor) {
|
||||||
|
let editor = "";
|
||||||
|
if (argsEditor) {
|
||||||
|
editor = argsEditor;
|
||||||
|
/* eslint-disable */
|
||||||
|
} else if (process.env.EDITOR) {
|
||||||
|
editor = process.env.EDITOR;
|
||||||
|
} else if (process.env.VISUAL) {
|
||||||
|
editor = process.env.VISUAL
|
||||||
|
/* eslint-enable */
|
||||||
|
// needed for the process.env statements to not be flagged by eslint
|
||||||
|
// prio for editors is CLI arg > env.EDITOR > env.VISUAL
|
||||||
|
} else {
|
||||||
|
editor = -1;
|
||||||
|
}
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
async function configToKeyVal(data) {
|
async function configToKeyVal(data) {
|
||||||
let final = {};
|
let final = {};
|
||||||
let splitData = data.split(/\r?\n/);
|
let splitData = data.split(/\r?\n/);
|
||||||
@@ -141,22 +159,11 @@ masterConfigCommands.add(new libCommand.Command({
|
|||||||
handler: async function(args, control) {
|
handler: async function(args, control) {
|
||||||
let response = await libLink.messages.getMasterConfig.send(control);
|
let response = await libLink.messages.getMasterConfig.send(control);
|
||||||
let tmpFile = await libFileOps.getTempFile("ctl-", "-tmp", os.tmpdir());
|
let tmpFile = await libFileOps.getTempFile("ctl-", "-tmp", os.tmpdir());
|
||||||
let editor = 0;
|
let editor = await getEditor(args.editor);
|
||||||
if (args.editor) {
|
if (editor === -1) {
|
||||||
editor = args.editor;
|
|
||||||
/* eslint-disable */
|
|
||||||
} else if (process.env.EDITOR) {
|
|
||||||
editor = process.env.EDITOR;
|
|
||||||
} else if (process.env.VISUAL) {
|
|
||||||
editor = process.env.VISUAL
|
|
||||||
/* eslint-enable */
|
|
||||||
// needed for the process.env statements to not be flagged by eslint
|
|
||||||
// prio for editors is CLI arg > env.EDITOR > env.VISUAL
|
|
||||||
} else {
|
|
||||||
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 = "";
|
||||||
for (let group of response.serialized_config.groups) {
|
for (let group of response.serialized_config.groups) {
|
||||||
for (let [name, value] of Object.entries(group.fields)) {
|
for (let [name, value] of Object.entries(group.fields)) {
|
||||||
@@ -423,22 +430,11 @@ instanceConfigCommands.add(new libCommand.Command({
|
|||||||
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
let instanceId = await libCommand.resolveInstance(control, args.instance);
|
||||||
let response = await libLink.messages.getInstanceConfig.send(control, { instance_id: instanceId });
|
let response = await libLink.messages.getInstanceConfig.send(control, { instance_id: instanceId });
|
||||||
let tmpFile = await libFileOps.getTempFile("ctl-", "-tmp", os.tmpdir());
|
let tmpFile = await libFileOps.getTempFile("ctl-", "-tmp", os.tmpdir());
|
||||||
let editor = 0;
|
let editor = await getEditor(args.editor);
|
||||||
if (args.editor) {
|
if (editor === -1) {
|
||||||
editor = args.editor;
|
|
||||||
/* eslint-disable */
|
|
||||||
} else if (process.env.EDITOR) {
|
|
||||||
editor = process.env.EDITOR;
|
|
||||||
} else if (process.env.VISUAL) {
|
|
||||||
editor = process.env.VISUAL
|
|
||||||
/* eslint-enable */
|
|
||||||
// needed for the process.env statements to not be flagged by eslint
|
|
||||||
// prio for editors is CLI arg > env.EDITOR > env.VISUAL
|
|
||||||
} else {
|
|
||||||
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 instance config edit <instance> <editor of choice>"`);
|
Try "ctl master config edit <editor of choice>"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
for (let group of response.serialized_config.groups) {
|
||||||
|
|||||||
Reference in new issue
Block a user