Skip to content

Commit ccb949f

Browse files
committed
fix npm cli issue
1 parent e72f97b commit ccb949f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

bin/index.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,27 @@ const { argv } = yargs
8080
.help('help');
8181

8282
argv.countryCode = argv.country;
83-
if (argv.states === 'US') {
84-
getUsaStats(argv).then(result => {
85-
console.log(result);
86-
process.exit(1);
87-
}).catch(error => {
88-
console.error(error);
89-
process.exit(0);
90-
});
83+
if (argv.states) {
84+
const country = lookupCountry(argv.states);
85+
if (!country) {
86+
let error = `Country '${argv.states}' not found.\n`;
87+
error += 'Try full country name or country code.\n';
88+
error += 'Ex:\n';
89+
error += '- UK: for United Kingdom \n';
90+
error += '- US: for United States of America.\n';
91+
error += '- Italy: for Italy.\n';
92+
throw new Error(chalk.red.bold(error));
93+
}
94+
argv.countryCode = country.iso2;
95+
if (argv.countryCode === 'US') {
96+
getUsaStats(argv).then(result => {
97+
console.log(result);
98+
process.exit(1);
99+
}).catch(error => {
100+
console.error(error);
101+
process.exit(0);
102+
});
103+
}
91104
}
92105

93106
if (argv.source === 1) {
@@ -98,7 +111,7 @@ if (argv.source === 1) {
98111
).then(console.log).catch(console.error);
99112
}
100113
else if (argv.graph === true) {
101-
getGraph(argv.countryCode).then(console.log).catch(console.error);
114+
getGraph(argv).then(console.log).catch(console.error);
102115
} else {
103116
getWorldoMetersTable(argv).then(console.log).catch(console.error);
104117
}

0 commit comments

Comments
 (0)