configManager.js - more useful return values

This commit is contained in:
Daniel Vestøl committed 2018-08-11 19:59:35 +02:00
1 parent 5630f7f7f6
commit 1faa3671e4
2 files changed
+13 -3

No files matched your search

+12 -1
View File
@@ -15,6 +15,9 @@ console.log()s each entry in the config
@param {string} instance Either undefined, "shared" or the instance to show the config for.
*/
module.exports.displayConfig = function(instance){
console.log(asTable(this.getConfig(instance)));
}
module.exports.getConfig = async function(instance){
if(!instance || instance == "shared"){
let configArray = [];
Object.keys(config).forEach(key=>{
@@ -24,7 +27,7 @@ module.exports.displayConfig = function(instance){
} else configArray.push({entry: key, value: config[key]});
}
});
console.log(asTable(configArray));
return configArray;
}
}
module.exports.editConfig = function(instance, entry, newValue){
@@ -36,12 +39,20 @@ module.exports.editConfig = function(instance, entry, newValue){
console.log("new config file:");
console.log(JSON.stringify(config, null, " "))
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
return {
ok:true,
msg:`Changed config entry ${entry} from Object to ${JSON.stringify(newValue)}`,
}
} else {
config[entry] = newValue;
console.log("Changed config entry "+entry+" from "+config[entry]+" to '"+newValue+"'");
console.log("new config file:");
console.log(JSON.stringify(config, null, " "))
fs.writeFileSync("config.json", JSON.stringify(config, null, 4));
return {
ok:true,
msg:`Changed config entry ${entry} from ***** to '${newValue}'`,
};
}
}
}