@@ -13,9 +13,13 @@ import {
1313 historyPerCountryPlain ,
1414 informationPerCountryPlain ,
1515} from "./utils/routes/plain/plainHandlers" ;
16+ import {
17+ countryDashboard ,
18+ globalDashboard ,
19+ } from "./utils/routes/dashboard/dashboardHandlers" ;
1620
1721const args = argv ( process . argv . slice ( 2 ) ) ;
18- let { history, mode, help, quiet, plain } = args ;
22+ let { dashboard , history, mode, help, quiet, plain, size } = args ;
1923const country = args . _ [ 0 ] ;
2024
2125const helpMessage = `${ welcomeMessage }
@@ -26,8 +30,10 @@ Country: Can be a country name or ISO 3166-1 alpha-2 country code
2630 Leave empty to show global data
2731
2832Options:
33+ --dashboard Show a dashboard
34+ --size Use with --dashboard to control the size of the output
2935 --history Show a chart of country's cases of world's cases
30- --mode Use with --history to make show a chart of cases, deaths, or recovered
36+ --mode Use with --history to show a chart of cases, deaths, or recovered
3137 --quiet Only show necessary information
3238 --plain Enable plain mode
3339
@@ -36,22 +42,28 @@ Useful Links:
3642 ${ lines . WNrepoLink }
3743 ${ lines . WNDonateLink } ` ;
3844
39- let output : string = "" ;
40- const main = async ( ) => {
41- if ( help ) return console . log ( helpMessage ) ;
45+ const main : ( ) => Promise < string > = async ( ) => {
46+ if ( help ) return helpMessage ;
4247 quiet = quiet === undefined ? false : quiet ;
4348
49+ if ( dashboard ) {
50+ if ( size === undefined ) size = "sm" ;
51+ if ( ! [ "sm" , "md" , "lg" ] . includes ( size ) ) size = "sm" ;
52+
53+ return country === undefined
54+ ? await globalDashboard ( size , false )
55+ : await countryDashboard ( country , size , false ) ;
56+ }
57+
4458 if ( history === undefined ) {
4559 if ( country === undefined ) {
46- output =
47- plain === true
48- ? await globalInformationPlain ( quiet )
49- : await globalInformation ( quiet ) ;
60+ return plain === true
61+ ? await globalInformationPlain ( quiet )
62+ : await globalInformation ( quiet ) ;
5063 } else {
51- output =
52- plain === true
53- ? await informationPerCountryPlain ( country , quiet )
54- : await informationPerCountry ( country , quiet ) ;
64+ return plain === true
65+ ? await informationPerCountryPlain ( country , quiet )
66+ : await informationPerCountry ( country , quiet ) ;
5567 }
5668 }
5769
@@ -60,25 +72,32 @@ const main = async () => {
6072
6173 if ( history ) {
6274 if ( country === undefined ) {
63- output =
64- plain === true
65- ? await globalHistoryPlain ( mode , quiet )
66- : await globalHistory ( mode , quiet ) ;
75+ return plain === true
76+ ? await globalHistoryPlain ( mode , quiet )
77+ : await globalHistory ( mode , quiet ) ;
6778 } else {
68- output =
69- plain === true
70- ? await historyPerCountryPlain ( country , mode , quiet )
71- : await historyPerCountry ( country , mode , quiet ) ;
79+ return plain === true
80+ ? await historyPerCountryPlain ( country , mode , quiet )
81+ : await historyPerCountry ( country , mode , quiet ) ;
7282 }
7383 }
7484
75- // remove magic? newline
76- let response = output . split ( "\n" ) ;
77- response . pop ( ) ;
78-
79- console . log ( response . join ( "\n" ) ) ;
85+ return "" ;
8086} ;
8187
82- main ( ) . catch ( ( err ) => {
83- console . log ( err . message + "\n" ) ;
84- } ) ;
88+ ( async ( ) => {
89+ let response = await main ( ) . catch ( ( err ) => {
90+ // Log error and exit out
91+ console . log ( err . message + "\n" ) ;
92+ process . exit ( ) ;
93+ } ) ;
94+
95+ //Remove magic new lines
96+ let responseArray = response . split ( "\n" ) ;
97+ while ( ! / \S / . test ( responseArray [ responseArray . length - 1 ] ) ) {
98+ responseArray . pop ( ) ;
99+ }
100+ response = responseArray . join ( "\n" ) + "\n" ;
101+
102+ console . log ( response ) ;
103+ } ) ( ) ;
0 commit comments