-
-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEW: Add omit column feature #46
base: master
Are you sure you want to change the base?
Changes from all commits
f90cd38
a11c1a9
366de33
1b524f0
3739ac2
5e5833c
24e8948
e8dfd9a
c1ccb65
d629f44
1055dd5
a173819
1efdf2e
613272f
a9be0e2
a816249
73bf769
a3e2b7a
8a97328
55e2463
c91b85b
cea6dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,23 +38,23 @@ const options = { sortBy, limit, reverse, minimal }; | |
init(minimal); | ||
const [input] = cli.input; | ||
input === 'help' && (await cli.showHelp(0)); | ||
const states = input === 'states' ? true : false; | ||
const states = input === 'states'; | ||
const country = input; | ||
|
||
// Table | ||
const head = xcolor ? single : colored; | ||
const headStates = xcolor ? singleStates : coloredStates; | ||
|
||
const border = minimal ? borderless : {}; | ||
const table = !states | ||
? new Table({ head, style, chars: border }) | ||
: new Table({ head: headStates, style, chars: border }); | ||
const tableHead = states ? headStates : head; | ||
const table = new Table({ head: tableHead, style, chars: border }); | ||
Comment on lines
-48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic for table was complex - it started with negation even though there was no real reason for it. As I needed this piece of code I refactored it a little bit for easier maintenance. |
||
|
||
// Display data. | ||
spinner.start(); | ||
const lastUpdated = await getWorldwide(table, states); | ||
await getCountry(spinner, table, states, country); | ||
await getStates(spinner, table, states, options); | ||
await getCountries(spinner, table, states, country, options); | ||
await getCountry({ spinner, table, states, country, tableHead }); | ||
await getStates({ spinner, table, states, options, tableHead }); | ||
await getCountries({ spinner, table, states, country, options, tableHead }); | ||
Comment on lines
-55
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due to multiple parameters I refactored |
||
|
||
theEnd(lastUpdated, states, minimal); | ||
})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module.exports = { | ||
single: { | ||
'#': 0, | ||
country: 1, | ||
cases: 2, | ||
'cases-today': 3, | ||
deaths: 4, | ||
'deaths-today': 5, | ||
recovered: 6, | ||
active: 7, | ||
critical: 8, | ||
'per-milion': 9 | ||
}, | ||
colored: { | ||
'#': 0, | ||
country: 1, | ||
cases: 2, | ||
'cases-today': 3, | ||
deaths: 4, | ||
'deaths-today': 5, | ||
recovered: 6, | ||
active: 7, | ||
critical: 8, | ||
'per-milion': 9 | ||
}, | ||
singleStates: { | ||
'#': 0, | ||
state: 1, | ||
cases: 2, | ||
'cases-today': 3, | ||
deaths: 4, | ||
'deaths-today': 5, | ||
active: 6 | ||
}, | ||
coloredStates: { | ||
'#': 0, | ||
state: 1, | ||
cases: 2, | ||
'cases-today': 3, | ||
deaths: 4, | ||
'deaths-today': 5, | ||
active: 6 | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const mapper = require('./columnsMapper'); | ||
const cli = require('./cli'); | ||
|
||
// returns indices of table rows which user wants to omit form output in descending order | ||
const parseCli = (states, separator = '_') => { | ||
const input = cli.flags.omit; | ||
if (!input || typeof input !== 'string') return []; | ||
return input | ||
.split(separator) | ||
.reduce((accumulator, current) => { | ||
if (states) { | ||
return mapper.singleStates[current] | ||
? [...accumulator, mapper.singleStates[current]] | ||
: accumulator; | ||
} | ||
return mapper.single[current] | ||
? [...accumulator, mapper.single[current]] | ||
: accumulator; | ||
}, []) | ||
.sort((a, b) => (a > b ? -1 : 1)); | ||
}; | ||
|
||
const deleteColumns = (table, tableHead, input) => { | ||
input.forEach((key) => { | ||
tableHead.splice(key, 1); | ||
table.forEach((row) => { | ||
row.splice(key, 1); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
parseCli, | ||
deleteColumns | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same code written simpler.