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

feat: Add dangerous mode to avoid node version check #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ assets/img/.DS_Store
package-lock.json
yarn.lock
settings.dat

# Visual Studio Code debug files
.vscode/
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ const limit = Math.abs(cli.flags.limit);
const chart = cli.flags.chart;
const log = cli.flags.log;
const minimal = cli.flags.minimal;
const dangerous = cli.flags.dangerous;
const options = { sortBy, limit, reverse, minimal, chart, log };

(async () => {
// Init.
init(minimal);
init(dangerous);
Copy link
Owner

Choose a reason for hiding this comment

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

This is wrong. You remove minimal option all together.

Copy link
Author

Choose a reason for hiding this comment

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

@ahmadawais : Sorry I did not get you. minimal option is not used inside the init module at all. That is the reason I removed it from the call.

input === 'help' && (await cli.showHelp(0));
const states = input === 'states' ? true : false;
const country = input;
Expand Down
8 changes: 8 additions & 0 deletions utils/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = meow(
${yellow(`--log`)}, ${yellow(`-g`)} Print logarithmic chart
${yellow(`--xcolor`)}, ${yellow(`-x`)} Single colored output
${yellow(`--minimal`)}, ${yellow(`-m`)} Minimalistic CLI output
${yellow(`--dangerous`)}, ${yellow(
`-d`
)} Avoids node version check when launching the cli

Examples
${green(`corona`)} ${cyan(`china`)}
Expand Down Expand Up @@ -72,6 +75,11 @@ module.exports = meow(
type: 'boolean',
default: false,
alias: 'm'
},
dangerous: {
type: 'boolean',
default: false,
alias: 'd'
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions utils/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ const pkgJSON = require('./../package.json');
const updateNotifier = require('update-notifier');
const unhandledError = require('cli-handle-unhandled');

module.exports = async () => {
const MINIMUM_NODE_JS_VERSION = '10';

module.exports = async dangerous => {
unhandledError();
checkNode(`10`);
if (!dangerous) {
Copy link
Owner

Choose a reason for hiding this comment

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

You didn't handle the case when dangerous-version flag is set.

Copy link
Author

Choose a reason for hiding this comment

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

@ahmadawais : By default, dangerous is false. I have added the logic in such a way that checkNode is called only if dangerous flag is not set. If dangerous is set, it will not go inside the if block at all. Does it make sense?

checkNode(MINIMUM_NODE_JS_VERSION);
}
welcome(`corona-cli`, `by Awais.dev\n${pkgJSON.description}`, {
bgColor: `#007C91`,
color: `#FFFFFF`,
Expand Down