Skip to content

Commit c0af963

Browse files
committed
fix changes to country filter on cli, changes to readme
1 parent c94932f commit c0af963

File tree

7 files changed

+136
-43
lines changed

7 files changed

+136
-43
lines changed

bin/index.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
11
#!/usr/bin/env node
2-
2+
const yargonaut = require('yargonaut')
3+
.style('green');
4+
const yargs = require('yargs');
5+
const chalk = require('chalk');
36
const { getCompleteTable } = require('../lib/corona');
47
const { getCountryTable } = require('../lib/byCountry');
58
const { lookupCountry } = require('../lib/helpers');
69

7-
const {argv} = require('yargs')
8-
.command('$0 [country]', 'show COVID-19 statistics for the world or the given country', yargs =>
10+
const { argv } = yargs
11+
.command('$0 [country]','Tool to COVID-19 statistics for the world or the given country', yargs =>
912
yargs.positional('country', {
1013
coerce(arg) {
11-
console.log(arg);
12-
if('ALL' === arg.toUpperCase()) {
14+
if ('ALL' === arg.toUpperCase()) {
1315
return 'ALL';
1416
}
15-
1617
const country = lookupCountry(arg);
17-
18-
if(!country) {
19-
throw new Error(`Country '${arg}' not found.
20-
Try full country name or country code.
21-
Ex:
22-
- UK: for United Kingdom
23-
- US: for United States of America.
24-
- India: for India.`);
18+
if (!country) {
19+
let error = `Country '${arg}' not found.\n`;
20+
error += 'Try full country name or country code.\n';
21+
error += 'Ex:\n';
22+
error += '- UK: for United Kingdom \n';
23+
error += '- US: for United States of America.\n';
24+
error += '- Italy: for Italy.\n';
25+
throw new Error(chalk.red.bold(error));
2526
}
26-
2727
return country.iso2;
2828
},
29-
describe: 'which country to show statistics for',
29+
describe: 'Filter table by country',
3030
default: 'all',
3131
type: 'string'
3232
})
3333
)
3434
.options({
3535
e: {
3636
alias: 'emojis',
37-
describe: 'enable the use of emojis in the table (may break alignment in some terminals)',
37+
describe: 'Show emojis in table',
3838
default: false,
3939
type: 'boolean'
4040
},
4141
c: {
4242
alias: 'color',
43-
describe: 'enable the use of color in the table.',
43+
describe: 'Show colors formatted output',
4444
type: 'boolean'
4545
}
4646
})
4747
.strict()
4848
.help('help');
4949

50-
(country === 'all' ? getCompleteTable(argv) : getCountryTable(country, argv))
50+
const { emojis, country } = argv;
51+
(
52+
country === 'ALL'
53+
? getCompleteTable(emojis)
54+
: getCountryTable(country, emojis)
55+
)
5156
.then(console.log)
5257
.catch(console.error);

lib/byCountry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ exports.getJSONDataForCountry = async (countryCode) => {
7979
return countryData;
8080
}
8181

82-
exports.getCountryTable = async (countryCode, {emojis=false}={}) => {
82+
exports.getCountryTable = async (countryCode, emojis = false) => {
8383
const head = [
8484
'',
8585
'State',

lib/corona.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ function extraStats(dataArr) {
7979
);
8080
}
8181

82-
exports.getCompleteTable = async ({emojis=false}={}) => {
82+
exports.getCompleteTable = async (emojis = false) => {
8383
const head = [
8484
'',
8585
'Country',
86-
'Confirmed',
86+
`Confirmed ${emojis ? ' ✅': ''}`,
8787
`Recovered${emojis ? ' 😀' : ''}`,
8888
`Deaths${emojis ? ' 😞' : ''}`,
8989
`Active${emojis ? ' 😷' : ''}`,
@@ -117,7 +117,7 @@ exports.getCompleteTable = async ({emojis=false}={}) => {
117117
getOneDayChange(worldStats),
118118
getOneWeekChange(worldStats),
119119
// '',
120-
... ( emojis ? ['🌎'] : [] )
120+
...( emojis ? ['🌎'] : [] )
121121
]
122122
})
123123
let rank = 1;
@@ -134,7 +134,7 @@ exports.getCompleteTable = async ({emojis=false}={}) => {
134134
getOneDayChange(cd),
135135
getOneWeekChange(cd),
136136
// getRateOfGrowth(cd),
137-
... (emojis ? [countryEmoji] : [])
137+
...(emojis ? [countryEmoji] : [])
138138
]
139139
table.push({ [rank++]: values })
140140
});

lib/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ e.lookupCountry = country => {
162162
} catch (error) {
163163
return lookup.byFips(country) || lookup.byCountry(country);
164164
}
165-
}
165+
};
166166

167167
e.footer = (lastUpdated) => `
168168

package-lock.json

Lines changed: 73 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coronavirus-tracker-cli",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "track conronavirus cases from cli",
55
"main": "./lib/corona.js",
66
"bin": {
@@ -29,6 +29,7 @@
2929
"moment": "^2.24.0",
3030
"morgan": "^1.9.1",
3131
"node-cache": "^5.1.0",
32+
"yargonaut": "^1.1.4",
3233
"yargs": "15.3.1"
3334
},
3435
"devDependencies": {

readme.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@ npm install coronavirus-tracker-cli -g
5151
corona
5252
````
5353

54-
**Top 10**
55-
56-
Note: This command will cause colored output to be discarded.
54+
**With emojis**
5755

5856
````sh
59-
# Grep the rank of 10 and the 23 lines preceding it
60-
corona | grep -B 23 ' 10 '
57+
corona -e
6158
````
6259

63-
**Your country**
60+
**Filter by country**
61+
62+
````sh
63+
corona italy
64+
````
6465

65-
Note: These commands will cause colored output to be discarded.
66+
**Disable colors**
6667

67-
- Replace the `US` part of the command with your country code.
68-
- If you want to also see the `World` stats, replace the `3` with a `5`
6968
````sh
70-
# sed the first 3 (or 5) lines; your country; bottom table border
71-
corona | sed -n '1,3p;/\(US\)/p;/╚═/p'
69+
corona --colors=false
7270
````
7371

74-
Or, get your country within context of your rank
72+
**Top 10** (Working on native command)
73+
74+
Note: This command will cause colored output to be discarded.
75+
7576
````sh
76-
# grep with 2 lines of context for each result
77-
# output the 'World' stats and headers; the country stats; the bottom table border
78-
corona | grep --color=none -C 2 -e 'World' -e '\(US\)' -e 'Stay'
77+
# Grep the rank of 10 and the 23 lines preceding it
78+
corona | grep -B 23 ' 10 '
7979
````
8080

8181
### ToDos
@@ -86,6 +86,22 @@ corona | grep --color=none -C 2 -e 'World' -e '\(US\)' -e 'Stay'
8686
* Add growth rate. (linear regression)
8787
* Add latest updates from reddit / twitter.
8888

89+
### Contributors
90+
91+
```
92+
project : curl-corona
93+
lines : 2821
94+
authors :
95+
2343 sagark 83.1%
96+
293 Alexandra Parker 10.4%
97+
120 Not Committed Yet 4.3%
98+
30 Lucas Fernandez Nicolau 1.1%
99+
25 Shelton Koskie 0.9%
100+
6 Mo'men Tawfik 0.2%
101+
3 XhmikosR 0.1%
102+
1 CyberDracula 0.0%
103+
```
104+
89105
### Other Regional Trackers.
90106

91107
* [Italy](http://opendatadpc.maps.arcgis.com/apps/opsdashboard/index.html#/b0c68bce2cce478eaac82fe38d4138b1)

0 commit comments

Comments
 (0)