-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (43 loc) · 1.22 KB
/
index.js
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
const formatters = {
days: parseInt,
day: parseInt,
testinput: (input) => input.toLowerCase() === "true",
windowssize: parseInt,
partone: (input) => input.toLowerCase() === "true",
};
function exit(error) {
console.error(error.toString());
process.exit(1);
}
async function run() {
let args = process.argv;
let day = null;
let testInput = false;
const arguments = [];
for (const arg of args) {
const temp = arg.replace(/-+/g, "");
let [param, value] = temp.split("=");
param = param.toLowerCase();
if (!formatters.hasOwnProperty(param)) continue;
value = formatters[param](value);
if (param === "day") {
day = value;
} else if (param === "testinput") {
testInput = value;
} else {
arguments.push(value);
}
}
if (!day) {
exit(new Error("--day Param is required!"));
}
const path = `./src/day_${day}/day_${day}`;
const computeDay = require(path);
let inputPath = `${path}.txt`;
if (testInput) {
inputPath = `./test/test_input/day_${day}.txt`;
}
const res = await computeDay(inputPath, ...arguments);
console.log(res);
}
run();