forked from chawlapalak/Url-Inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1.26 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
#!/usr/bin/env node
const restHandler = require("./utils/restHandler");
const program = require("commander");
const fileHandler = require("./utils/fileHandler");
program
.version("0.0.1", "-v, -V, --version ", "prints tool version") //user can use any of the command to know the version
.option("-f, --file <path>", "Path to file")
.option("--all", "All URLs")
.option("--good", "Good URLs")
.option("--bad", "Bad URLs")
.option("-i, --ignore <path>", "Path to file with URLs to ignore")
.option("-e, --endpoint <url>", "URL to fetch post list");
program.parse(process.argv);
if (program.ignore && !program.file) {
console.log("Error: Usage url-inspector -i <path> - f <filepath>");
}
if (program.file) {
console.log(`file: ${program.file}`);
const displayOption = program.bad ? "bad" : program.good ? "good" : "all";
fileHandler.readCheckFile(program.file, program.ignore, displayOption);
}
if (program.endpoint) {
console.log(`endpoint: ${program.endpoint}`);
restHandler
.resFetch(program.endpoint)
.then(() => {
fileHandler.readCheckFile("postsUrl.txt", undefined, "all");
})
.catch((err) => console.log(err));
}
process.on("exit", function (code) {
return console.log(`Finished checking all the URLs with end code ${code}`);
});