This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
69 lines (63 loc) · 1.53 KB
/
cli.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
#!/usr/bin/env node
/**
* Command line handler.
* nsync filter.txt [-o output] [-c config]
*/
"use strict";
/**
* Load modules.
* @const {Module}
*/
const nsync = require("./index.js");
(async () => {
// Parse options
let filter, output, config;
let lastFlag;
let args = process.argv.slice(2);
for (let arg of args) {
if (!filter) {
filter = arg;
continue;
}
if (arg.startsWith("-")) {
if (lastFlag !== undefined) {
console.error("Missing argument for option", lastFlag);
process.exit(1);
}
lastFlag = arg;
continue;
}
if (lastFlag === undefined) {
console.error("Missing flag");
process.exit(1);
}
switch (lastFlag) {
case "-o":
output = arg;
break;
case "-c":
config = arg;
break;
default:
console.error("Unknown option", lastFlag);
process.exit(1);
}
lastFlag = undefined;
}
if (!filter) {
console.error("Missing filter file");
process.exit(1);
}
// Create patch
try {
if (config) {
await nsync.ezPatch(filter, output, config);
} else {
await nsync.ezPatch(filter, output);
}
} catch (err) {
console.error("Something went wrong...");
console.error(err);
process.exit(1);
}
})();