forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
84 lines (72 loc) · 2.55 KB
/
cli.ts
File metadata and controls
84 lines (72 loc) · 2.55 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
import argv from "minimist";
import { lines, welcomeMessage } from "./utils/libs/getResponses";
import {
globalHistory,
globalInformation,
historyPerCountry,
informationPerCountry,
} from "./utils/routes/regular/regularHandlers";
import {
globalHistoryPlain,
globalInformationPlain,
historyPerCountryPlain,
informationPerCountryPlain,
} from "./utils/routes/plain/plainHandlers";
const args = argv(process.argv.slice(2));
let { history, mode, help, quiet, plain } = args;
const country = args._[0];
const helpMessage = `${welcomeMessage}
Usage: covid [COUNTRY] [OPTIONS...]
Country: Can be a country name or ISO 3166-1 alpha-2 country code
Ex: ph = Philippines, kr = South Korea
Leave empty to show global data
Options:
--history Show a chart of country's cases of world's cases
--mode Use with --history to make show a chart of cases, deaths, or recovered
--quiet Only show necessary information
--plain Enable plain mode
Useful Links:
${lines.docsLink}
${lines.WNrepoLink}
${lines.WNDonateLink}`;
let output: string = "";
const main = async () => {
if (help) return console.log(helpMessage);
quiet = quiet === undefined ? false : quiet;
if (history === undefined) {
if (country === undefined) {
output =
plain === true
? await globalInformationPlain(quiet)
: await globalInformation(quiet);
} else {
output =
plain === true
? await informationPerCountryPlain(country, quiet)
: await informationPerCountry(country, quiet);
}
}
mode = mode === undefined ? "cases" : mode; // default to cases if mode is not present
if (!["cases", "deaths", "recovered"].includes(mode)) mode === "cases"; // default to cases if mode is not cases | deaths | recovered
if (history) {
if (country === undefined) {
output =
plain === true
? await globalHistoryPlain(mode, quiet)
: await globalHistory(mode, quiet);
} else {
output =
plain === true
? await historyPerCountryPlain(country, mode, quiet)
: await historyPerCountry(country, mode, quiet);
}
}
// remove magic? newline
let response = output.split("\n");
response.pop();
console.log(response.join("\n"));
};
main().catch((err) => {
console.log(err.message + "\n");
});