11import argv from "minimist" ;
2- import { generateColorTable } from "./utils/generateTable" ;
32import {
43 globalHistory ,
54 globalInformation ,
65 historyPerCountry ,
76 informationPerCountry ,
87} from "./utils/handlers" ;
8+ import {
9+ globalHistoryPlain ,
10+ globalInformationPlain ,
11+ historyPerCountryPlain ,
12+ informationPerCountryPlain ,
13+ } from "./utils/plainHandlers" ;
914
1015const args = argv ( process . argv . slice ( 2 ) ) ;
11- let { history, mode, help } = args ;
16+ let { history, mode, help, quiet , plain } = args ;
1217const country = args . _ [ 0 ] ;
1318
1419const { version } = require ( "../package.json" ) ;
@@ -22,29 +27,49 @@ Country: Can be a country name or ISO 3166-1 alpha-2 country code
2227
2328Options:
2429 --history Show a chart of country's cases of world's cases
25- --mode Use with --history to make show a chart of cases, deaths, or recovered` ;
30+ --mode Use with --history to make show a chart of cases, deaths, or recovered
31+ --quiet Only show necessary information
32+ --plain Enable plain mode` ;
2633
2734let output : string = "" ;
2835const main = async ( ) => {
2936 if ( help ) return console . log ( helpMessage ) ;
37+ quiet = quiet === undefined ? false : quiet ;
3038
31- if ( history === undefined || typeof history === "undefined" ) {
32- if ( country === undefined ) output = await globalInformation ( ) ;
33- else output = await informationPerCountry ( country ) ;
39+ if ( history === undefined ) {
40+ if ( country === undefined ) {
41+ output =
42+ plain === true
43+ ? await globalInformationPlain ( quiet )
44+ : await globalInformation ( quiet ) ;
45+ } else {
46+ output =
47+ plain === true
48+ ? await informationPerCountryPlain ( country , quiet )
49+ : await informationPerCountry ( country , quiet ) ;
50+ }
3451 }
3552
36- mode = mode === undefined || typeof mode === "undefined" ? "cases" : mode ; // defauilt to cases if mode is not present
53+ mode = mode === undefined ? "cases" : mode ; // default to cases if mode is not present
3754 if ( ! [ "cases" , "deaths" , "recovered" ] . includes ( mode ) ) mode === "cases" ; // default to cases if mode is not cases | deaths | recovered
3855
3956 if ( history ) {
40- if ( country === undefined ) output = await globalHistory ( mode ) ;
41- else output = await historyPerCountry ( country , mode ) ;
57+ if ( country === undefined ) {
58+ output =
59+ plain === true
60+ ? await globalHistoryPlain ( mode , quiet )
61+ : await globalHistory ( mode , quiet ) ;
62+ } else {
63+ output =
64+ plain === true
65+ ? await historyPerCountryPlain ( country , mode , quiet )
66+ : await historyPerCountry ( country , mode , quiet ) ;
67+ }
4268 }
4369
4470 console . log ( output ) ;
4571} ;
4672
4773main ( ) . catch ( ( err ) => {
48- let errorTable = generateColorTable ( [ err . message ] , "red" ) ;
49- console . log ( errorTable ) ;
74+ console . log ( err . message + "\n" ) ;
5075} ) ;
0 commit comments