From 906b192683af8c87bd49ff7d94a8297536bf7426 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Sat, 11 Nov 2017 16:40:19 +0100 Subject: [PATCH] More work on command line tools #59 --- client.js | 22 +++++++++++++++------- lib/manager/configManager.js | 27 +++++++++++++++++++++++++++ lib/manager/modManager.js | 1 + 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/client.js b/client.js index a17554b9..3844b0c3 100644 --- a/client.js +++ b/client.js @@ -126,8 +126,14 @@ if (!command || command == "help" || command == "--help") { } else if (command == "manage"){ // console.log("Launching mod manager"); //const fullUsage = 'node client.js manage [instance, "shared"] ["mods", "config"] ...'; - function usage(instance, tool){ - return 'node client.js manage '+(instance || '[instance, "shared"]') +' '+ (tool || '["mods", "config"]') + ' ...'; + function usage(instance, tool, action){ + if(tool && tool == "mods"){ + console.log('node client.js manage '+instance+' '+tool+' ["list", "search", "update"]'); + } else if(tool && tool == "config") { + console.log('node client.js manage '+instance+' '+tool+' ["list", "edit"]'); + } else { + console.log('node client.js manage '+(instance || '[instance, "shared"]') +' '+ (tool || '["mods", "config"]') + ' ...'); + } } const modManagerUsage1 = 'node client.js manage '; const modManagerUsage2 = ' mods ["list", "update"]'; @@ -139,23 +145,25 @@ if (!command || command == "help" || command == "--help") { modManager.listMods(instance); } else if(action == "search"){ modManager.findMods(process.argv[6]); + } else if(action == "update"){ + modManager.updateAllMods(); } else { - console.log(modManagerUsage1 + instance + modManagerUsage2); + usage(instance, tool); } } else if(tool == "config"){ if(action == "list" || action == "show" || action == "display"){ configManager.displayConfig(instance); } else if(action == "edit"){ - + configManager.editConfig(instance, process.argv); } else { - console.log() + usage(instance, tool); } } else { - console.log(usage(instance)); + usage(instance); } } else { console.log('Usage:'); - console.log(usage(instance)); + usage(instance); } // process.exit(1); } else if (command == "delete") { diff --git a/lib/manager/configManager.js b/lib/manager/configManager.js index e69de29b..c0a50ba9 100644 --- a/lib/manager/configManager.js +++ b/lib/manager/configManager.js @@ -0,0 +1,27 @@ +/** +Provides tools for managing both masters and slaves config files. +@module configManager +*/ +// require modules +const asTable = require("as-table").configure({delimiter: ' | '}); + +// internal requires +const config = require("./../../config"); +/** +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){ + if(!instance || instance == "shared"){ + let configArray = []; + Object.keys(config).forEach(key=>{ + if(key != "__comment"){ + if(typeof config[key] == "object"){ + configArray.push({entry: key, value: JSON.stringify(config[key])}); + } else configArray.push({entry: key, value: config[key]}); + } + }); + console.log(asTable(configArray)); + } +} diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index 188e8c58..e7666e38 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -61,6 +61,7 @@ module.exports.listMods = function(instance){ token: config.token, require_ownership: false }).then(() => { + console.log("Mods shared by all instances:") factorioAPI.getInstalledMods().then(mods => { console.log(asTable(mods)); });