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, quiet } = args ;
16+ let { history, mode, help, quiet, plain } = args ;
1217const country = args . _ [ 0 ] ;
1318
1419const { version } = require ( "../package.json" ) ;
@@ -23,30 +28,48 @@ Country: Can be a country name or ISO 3166-1 alpha-2 country code
2328Options:
2429 --history Show a chart of country's cases of world's cases
2530 --mode Use with --history to make show a chart of cases, deaths, or recovered
26- --quiet Only show necessary information` ;
31+ --quiet Only show necessary information
32+ --plain Enable plain mode` ;
2733
2834let output : string = "" ;
2935const main = async ( ) => {
3036 if ( help ) return console . log ( helpMessage ) ;
31- quiet = quiet === undefined || typeof quiet === "undefined" ? false : quiet ;
37+ quiet = quiet === undefined ? false : quiet ;
3238
33- if ( history === undefined || typeof history === "undefined" ) {
34- if ( country === undefined ) output = await globalInformation ( quiet ) ;
35- else output = await informationPerCountry ( country , quiet ) ;
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+ }
3651 }
3752
38- 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
3954 if ( ! [ "cases" , "deaths" , "recovered" ] . includes ( mode ) ) mode === "cases" ; // default to cases if mode is not cases | deaths | recovered
4055
4156 if ( history ) {
42- if ( country === undefined ) output = await globalHistory ( mode , quiet ) ;
43- else output = await historyPerCountry ( country , mode , quiet ) ;
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+ }
4468 }
4569
4670 console . log ( output ) ;
4771} ;
4872
4973main ( ) . catch ( ( err ) => {
50- let errorTable = generateColorTable ( [ err . message ] , "red" ) ;
51- console . log ( errorTable ) ;
74+ console . log ( err . message + "\n" ) ;
5275} ) ;
0 commit comments