-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
46 lines (37 loc) · 1.43 KB
/
main.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
#!/usr/bin/env node
"use strict";
const { updateHosts } = require("./updateHosts.js");
const { restoreHosts } = require("./restoreHosts.js");
const appName = "Easy GitHub Hosts";
function main() {
let argv = process.argv.slice(2);
// Filter out Node.js specific flags
argv = argv.filter(arg => !arg.startsWith('--inspect') && !arg.startsWith('--inspect-brk'));
if (argv.length === 0) {
console.error(`${appName}: ERROR - No arguments provided.`);
console.info(`${appName}: Usage: node main.js <command>`);
console.info(`${appName}: Commands:`);
console.info(`${appName}: - update: Update the HOSTS file with GitHub IPs`);
console.info(`${appName}: - restore: Restore the HOSTS file from backup`);
process.exit(1);
}
const command = argv[0];
switch (command) {
case "update":
updateHosts();
break;
case "restore":
restoreHosts();
break;
default:
console.error(`${appName}: ERROR - Unknown command: ${command}`);
console.info(`${appName}: Usage: node main.js <command>`);
console.info(`${appName}: Commands:`);
console.info(`${appName}: - update: Update the HOSTS file with GitHub IPs`);
console.info(`${appName}: - restore: Restore the HOSTS file from backup`);
process.exit(1);
}
}
if (require.main === module) {
main();
}