forked from sagarkarira/coronavirus-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·88 lines (83 loc) · 2.24 KB
/
index.js
File metadata and controls
executable file
·88 lines (83 loc) · 2.24 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
85
86
87
88
#!/usr/bin/env node
require('yargonaut').style('green');
const yargs = require('yargs');
const chalk = require('chalk');
const { getCompleteTable, getGraph } = require('../lib/corona');
const { getCountryTable } = require('../lib/byCountry');
const { getWorldoMetersTable } = require('../lib/worldoMeters');
const { lookupCountry } = require('../lib/helpers');
const { argv } = yargs
.command('$0 [country]', 'Tool to track COVID-19 statistics from terminal', yargs =>
yargs.positional('country', {
coerce(arg) {
if (arg.toUpperCase() === 'ALL') {
return 'ALL';
}
const country = lookupCountry(arg);
if (!country) {
let error = `Country '${arg}' not found.\n`;
error += 'Try full country name or country code.\n';
error += 'Ex:\n';
error += '- UK: for United Kingdom \n';
error += '- US: for United States of America.\n';
error += '- Italy: for Italy.\n';
throw new Error(chalk.red.bold(error));
}
return country.iso2;
},
describe: 'Filter table by country',
default: 'all',
type: 'string'
})
)
.options({
s: {
alias: 'source',
describe: 'fetch data from other source',
default: 2,
type: 'int'
},
e: {
alias: 'emojis',
describe: 'Show emojis in table',
default: false,
type: 'boolean'
},
c: {
alias: 'color',
describe: 'Show colors formatted output',
type: 'boolean'
},
m: {
alias: 'minimal',
describe: 'Remove borders & padding from table',
type: 'boolean',
default: false,
},
t: {
alias: 'top',
describe: 'Filter table by rank',
type: 'int'
},
g: {
alias: 'graph',
describe: 'Get graph',
type: 'boolean',
default: false,
}
})
.strict()
.help('help');
argv.countryCode = argv.country;
if (argv.source === 1) {
(
argv.country === 'ALL'
? getCompleteTable(argv)
: getCountryTable(argv)
).then(console.log).catch(console.error);
}
else if (argv.graph === true) {
getGraph(argv.countryCode).then(console.log).catch(console.error);
} else {
getWorldoMetersTable(argv).then(console.log).catch(console.error);
}