-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
55 lines (44 loc) · 1.56 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
// Imports
const keyboard = require("./keyboard");
const mouse = require("./mouse");
const utility = require("./utility");
// Utility functions
function parseArguments() {
// Get the arguments
let args = [...process.argv.slice(0)];
let parseColorArgument = () => {
// Gets the color from the arguments
let color = args.find(x => /^[0-9A-Z]{6}$/gi.test(x));
if (!color) throw new Error("You need to provide a valid HEX color!\nEx: node index.js <color> <target?>");
// Parses the color
return utility.hexToRgb(color);
};
let parseTargetArgument = () => {
// Gets the target of which the color will be applied
let target = args.find(x => /^(keyboard|mouse|both)$/i.test(x)) || "both";
if (!target) throw new Error("You need to provida a valid target for the color to be applied onto!");
return target;
};
return {
color: parseColorArgument(),
target: parseTargetArgument()
};
}
// Execution
function main() {
// Parse arguments
let args = parseArguments();
console.log(`Setting color rgb(${args.color.red}, ${args.color.green}, ${args.color.blue}) into ${args.target} device(s)`);
// Set the keyboard color
if (args.target == "keyboard" || args.target == "both") {
console.log("Setting keyboard color...");
keyboard(args.color);
}
// Set the mouse color
if (args.target == "mouse" || args.target == "both") {
console.log("Setting mouse color...");
mouse(args.color);
}
console.log("Done!");
}
main();