forked from widdix/aws-cf-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·48 lines (42 loc) · 1.04 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
#!/usr/bin/env node
"use strict";
var checker = require("./index.js");
var fs = require("fs");
var argv = require("minimist")(process.argv.slice(2));
function checkCallback(err, findings) {
if (err) {
console.error(err.message);
process.exit(2);
} else {
if (findings.length > 0) {
findings.forEach(console.dir);
process.exit(1);
} else {
process.exit(0);
}
}
}
function checkFile(file, options) {
checker.checkFile(file, options, checkCallback);
}
function checkJSON(json, options) {
checker.checkTemplate(JSON.parse(json), options, checkCallback);
}
var checks = require("./checks.json");
if (argv.checksFile) {
var json = fs.readFileSync(argv.checksFile, {"encoding": "utf8"});
checks = JSON.parse(json);
}
if (argv.templateFile) {
checkFile(argv.templateFile, checks);
} else {
var data = "";
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function(chunk) {
data += chunk;
});
process.stdin.on("end", function() {
checkJSON(data, checks);
});
}