diff options
author | 0neGal <mail@0negal.com> | 2021-12-27 01:10:18 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2021-12-27 01:14:08 +0100 |
commit | ee7753c1e03fe74bc133ecbf7eb149fb53841f58 (patch) | |
tree | c6fa10188cc01c6c1ac31eb50816b5aa6d32e318 /src/cli.js | |
parent | df7b714d27e5d23a6ac3e381e6684856bc818d1c (diff) | |
download | Viper-ee7753c1e03fe74bc133ecbf7eb149fb53841f58.tar.gz Viper-ee7753c1e03fe74bc133ecbf7eb149fb53841f58.zip |
added working cli arguments
I think?
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) + } +} |