-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkactus.js
executable file
·50 lines (43 loc) · 1.23 KB
/
kactus.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
#!/usr/bin/env node
var command = process.argv[2];
var path = process.argv[3];
var usage = "Usage: `kactus import|parse|find path`";
if (!command) {
console.error("Missing command. " + usage);
process.exit(1);
}
if (
command !== "import" &&
command !== "parse" &&
command !== "find" &&
command !== "parseAll" &&
command !== "importAll" &&
command !== "createNew"
) {
console.error("Command " + command + " not recognized.");
console.error("Only `import` and `parse` are supported. " + usage);
process.exit(1);
}
if (!path) {
console.error("Missing path. " + usage);
process.exit(1);
}
function catcher(err) {
console.error(err);
process.exit(1);
}
if (command === "import") {
require("./lib/import")(path).catch(catcher);
} else if (command === "parse") {
require("./lib/parse")(path).catch(catcher);
} else if (command === "importAll") {
require("./lib/importAll")(path).catch(catcher);
} else if (command === "parseAll") {
require("./lib/parseAll")(path).catch(catcher);
} else if (command === "find") {
require("./lib/find")(path)
.then((result) => console.log(JSON.stringify(result, null, "\t")))
.catch(catcher);
} else if (command === "createNew") {
require("./lib/createNew")(path).catch(catcher);
}