aboutsummaryrefslogtreecommitdiff
path: root/src/cli.js
blob: b550a8f577c0d543794630522475a4d7a78a49b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)
	}
}