-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·97 lines (90 loc) · 2.92 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
var nlc = require("network-link-conditioner");
var args = require('minimist')(process.argv.slice(2));
const chalk = require('chalk');
var figlet = require('figlet');
cli(args);
async function cli(args) {
let cmd = args._[0] || 'help';
if (cmd == "v" || cmd == "-v") {
cmd = 'version';
}
if (cmd == "h" || cmd == "-h") {
cmd = 'help';
}
if (cmd == "-p") {
cmd = 'profiles';
}
if (cmd == "-s") {
cmd = 'set';
}
switch (cmd) {
case 'version':
const package = require("./package.json");
console.log("The current version is: " + package.version);
break;
case 'help':
help(args);
break;
case 'on':
await nlc.on();
break;
case 'off':
await nlc.off();
break;
case 'profiles':
try {
const profiles = await nlc.getProfileNames();
for (const profile of profiles) {
console.log(profile);
}
} catch (e) {
console.error(chalk.red("Error getting profiles."))
console.error(e.stderr);
}
break;
case 'set':
if (args._[1] == undefined || args._[1] == null || args._[1] == "") {
console.log('no profile specified. Try Try "nlc help" for more infos.');
return;
}
var profile = args._[1];
try {
await nlc.setProfile(profile);
} catch (e) {
console.error(chalk.red("Error setting profile."));
console.error(e.stderr);
}
break;
case 'close':
nlc.closeSystemPreferences();
break
default:
console.error(chalk.red(`"${cmd}" is not a valid command. Try "nlc help" for more infos.`));
break;
}
}
function help(args) {
figlet('NLC Help', function (err, data) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(chalk.green(data))
console.log("Network Link Conditioner CLI");
console.log("")
console.log(chalk.yellow("Commands"));
console.log(chalk.cyan("on") + " : Turns the Network Link Conditioner on.")
console.log(chalk.cyan("off") + " : Turns the Network Link Conditioner off.")
console.log(chalk.cyan("profiles") + " : Shows all available profiles.")
console.log(chalk.cyan("set [profile]") + " : Sets a profile.")
console.log(chalk.cyan("close") + " : Closes the system preferences.")
console.log(chalk.cyan("help") + " : Shows this.")
console.log("")
console.log(chalk.yellow("Examples"));
console.log("nlc on")
console.log("nlc set 3G")
console.log("")
});
}