Skip to content
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: NonVerbose #41

Merged
merged 4 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
process.on('unhandledRejection', (err) => {
handleError(`UNHANDLED ERROR`, err);
});

Expand All @@ -19,21 +19,23 @@ const getCountry = require('./utils/getCountry.js');
const getWorldwide = require('./utils/getWorldwide.js');
const getCountries = require('./utils/getCountries.js');
const {
style,
single,
colored,
singleStates,
coloredStates,
style
borderless,
} = require('./utils/table.js');
const xcolor = cli.flags.xcolor;
const sortBy = cli.flags.sort;
const reverse = cli.flags.reverse;
const limit = Math.abs(cli.flags.limit);
const options = { sortBy, limit, reverse };
const minimal = cli.flags.minimal;
const options = { sortBy, limit, reverse, minimal };

(async () => {
// Init.
init();
init(minimal);
const [input] = cli.input;
input === 'help' && (await cli.showHelp(0));
const states = input === 'states' ? true : false;
Expand All @@ -42,9 +44,10 @@ const options = { sortBy, limit, reverse };
// Table
const head = xcolor ? single : colored;
const headStates = xcolor ? singleStates : coloredStates;
const border = minimal ? borderless : {};
const table = !states
? new Table({ head, style })
: new Table({ head: headStates, style });
? new Table({ head, style, chars: border })
: new Table({ head: headStates, style, chars: border });

// Display data.
spinner.start();
Expand All @@ -53,5 +56,5 @@ const options = { sortBy, limit, reverse };
await getStates(spinner, table, states, options);
await getCountries(spinner, table, states, country, options);

theEnd(lastUpdated, states);
!minimal && theEnd(lastUpdated, states);
})();
17 changes: 11 additions & 6 deletions utils/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,28 @@ module.exports = meow(
xcolor: {
type: 'boolean',
default: false,
alias: 'x'
alias: 'x',
},
sort: {
type: 'string',
default: 'cases',
alias: 's'
alias: 's',
},
vzsky marked this conversation as resolved.
Show resolved Hide resolved
reverse: {
type: 'boolean',
default: false,
alias: 'r'
alias: 'r',
},
limit: {
type: 'number',
default: Number.MAX_SAFE_INTEGER,
alias: 'l'
}
}
alias: 'l',
},
minimal: {
type: 'boolean',
defualt: false,
alias: 'm',
},
},
}
);
3 changes: 2 additions & 1 deletion utils/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const welcome = require('cli-welcome');
const pkgJSON = require('./../package.json');
const updateNotifier = require('update-notifier');

module.exports = async () => {
module.exports = async (quiet) => {
if (quiet) return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change it to quiet now?

welcome(`corona-cli`, `by Awais.dev\n${pkgJSON.description}`, {
bgColor: `#007C91`,
color: `#FFFFFF`,
Expand Down
17 changes: 17 additions & 0 deletions utils/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ module.exports = {
`${yellow(`Active`)}`,
],
style: { head: ['cyan'] },
borderless: {
top: '',
'top-mid': '',
'top-left': '',
'top-right': '',
bottom: '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
left: '',
'left-mid': '',
mid: '',
'mid-mid': '',
right: '',
'right-mid': '',
middle: ' ',
},
sortingKeys: {
country: 'country',
cases: 'cases',
Expand Down
3 changes: 2 additions & 1 deletion utils/theEnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ ${dim(`❯ `)}${cyan(`Per Million:`)} Affected patients per million
`)
);

module.exports = async (lastUpdated, states) => {
module.exports = async (lastUpdated, states, quiet) => {
if (quiet) return
console.log(dim(`${sym.info} ${cyan(`Last Updated:`)} ${lastUpdated}`));
states && infoStates();
!states && infoCountries();
Expand Down