diff options
Diffstat (limited to 'src/cli.js')
-rw-r--r-- | src/cli.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 0000000..b550a8f --- /dev/null +++ b/src/cli.js @@ -0,0 +1,55 @@ +const fs = require("fs"); +const { app, ipcMain } = require("electron"); + +const Emitter = require("events"); +const events = new Emitter(); + +const cli = app.commandLine; + +function hasArgs() { + if (cli.hasSwitch("cli") || + cli.hasSwitch("help") || + cli.hasSwitch("update") || + cli.hasSwitch("setpath") || + cli.hasSwitch("gamepath")) { + return true; + } else {return false} +} + +function exit(code) { + if (hasArgs()) {process.exit(code)} +} + +async function init() { + if (cli.hasSwitch("help")) { + console.log(`options: + --help shows this help message + + --cli forces the CLI to enable + --update updates Northstar from your set game path + --setpath sets your game path`) + // In the future --setpath should be able to understand + // relative paths, instead of just absolute ones. + exit(); + } + + if (cli.hasSwitch("update")) { + ipcMain.emit("update"); + } + + if (cli.hasSwitch("setpath")) { + if (cli.getSwitchValue("setpath") != "") { + ipcMain.emit("setpathcli", cli.getSwitchValue("setpath")); + } else { + console.error("error: No argumment provided for --setpath"); + } + } +} + +module.exports = { + hasArgs, + init, exit, + param: (arg) => { + return cli.getSwitchValue(arg) + } +} |