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
·57 lines (55 loc) · 1.54 KB
/
index.js
File metadata and controls
executable file
·57 lines (55 loc) · 1.54 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
#!/usr/bin/env node
const yargonaut = require('yargonaut')
.style('green');
const yargs = require('yargs');
const chalk = require('chalk');
const { getCompleteTable } = require('../lib/corona');
const { getCountryTable } = require('../lib/byCountry');
const { lookupCountry } = require('../lib/helpers');
const { argv } = yargs
.command('$0 [country]','Tool to COVID-19 statistics for the world or the given country', yargs =>
yargs.positional('country', {
coerce(arg) {
if ('ALL' === arg.toUpperCase()) {
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({
e: {
alias: 'emojis',
describe: 'Show emojis in table',
default: false,
type: 'boolean'
},
c: {
alias: 'color',
describe: 'Show colors formatted output',
type: 'boolean'
}
})
.strict()
.help('help');
const { emojis, country } = argv;
(
country === 'ALL'
? getCompleteTable(emojis)
: getCountryTable(country, emojis)
)
.then(console.log)
.catch(console.error);