diff --git a/index.js b/index.js index 053222e..90d8781 100755 --- a/index.js +++ b/index.js @@ -31,13 +31,14 @@ const { // Cli. const [input] = cli.input; const xcolor = cli.flags.xcolor; +const stateName = cli.flags.stateName; const sortBy = cli.flags.sort; const reverse = cli.flags.reverse; const limit = Math.abs(cli.flags.limit); const chart = cli.flags.chart; const log = cli.flags.log; const minimal = cli.flags.minimal; -const options = { sortBy, limit, reverse, minimal, chart, log }; +const options = { stateName, sortBy, limit, reverse, minimal, chart, log }; (async () => { // Init. diff --git a/readme.md b/readme.md index a9995c4..4c9470c 100644 --- a/readme.md +++ b/readme.md @@ -80,6 +80,11 @@ corona usa # Display data for all the US states. corona states +# Display data for single US state. +corona states --stateName Tennessee +or +corona states --stateName "New York" + # Display states data sorted by active cases. corona states --sort active diff --git a/utils/getStates.js b/utils/getStates.js index 4eaee68..b17a746 100644 --- a/utils/getStates.js +++ b/utils/getStates.js @@ -8,7 +8,7 @@ const to = require('await-to-js').default; const handleError = require('cli-handle-error'); const orderBy = require('lodash.orderby'); -module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { +module.exports = async (spinner, table, states, { stateName, sortBy, limit, reverse }) => { if (states) { const [err, response] = await to( axios.get(`https://corona.lmao.ninja/states`) @@ -24,17 +24,32 @@ module.exports = async (spinner, table, states, { sortBy, limit, reverse }) => { allStates = orderBy(allStates, [sortingStateKeys[sortBy]], [direction]); // Push selected data. - allStates.map((oneState, count) => { - table.push([ - count + 1, - oneState.state, - comma(oneState.cases), - comma(oneState.todayCases), - comma(oneState.deaths), - comma(oneState.todayDeaths), - comma(oneState.active) - ]); + if (stateName) { + allStates.map((oneState, count) => { + if (oneState.state === stateName) + table.push([ + '-', + oneState.state, + comma(oneState.cases), + comma(oneState.todayCases), + comma(oneState.deaths), + comma(oneState.todayDeaths), + comma(oneState.active) + ]); + }); + } + else { allStates.map((oneState, count) => { + table.push([ + count + 1, + oneState.state, + comma(oneState.cases), + comma(oneState.todayCases), + comma(oneState.deaths), + comma(oneState.todayDeaths), + comma(oneState.active) + ]); }); + }; spinner.stopAndPersist(); const isRev = reverse ? `${dim(` & `)}${cyan(`Order`)}: reversed` : ``;