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
50 lines (39 loc) · 1.66 KB
/
cli.ts
File metadata and controls
50 lines (39 loc) · 1.66 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
import argv from "minimist";
import { generateColorTable } from "./utils/generateTable";
import {
globalHistory,
globalInformation,
historyPerCountry,
informationPerCountry,
} from "./utils/handlers";
const args = argv(process.argv.slice(2));
let { history, mode, help } = args;
const country = args._[0];
const { version } = require("../package.json");
const helpMessage = `COVID-19 Tracker CLI v${version} by Waren Gonzaga with Wareneutron Developers
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`;
let output: string = "";
const main = async () => {
if (help) return console.log(helpMessage);
if (history === undefined || typeof history === "undefined") {
if (country === undefined) output = await globalInformation();
else output = await informationPerCountry(country);
}
mode = mode === undefined || typeof mode === "undefined" ? "cases" : mode; // defauilt 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 = await globalHistory(mode);
else output = await historyPerCountry(country, mode);
}
console.log(output);
};
main().catch((err) => {
let errorTable = generateColorTable([err.message], "red");
console.log(errorTable);
});