Skip to content

Commit d10bc1c

Browse files
LapinoLapidusjamesgeorge007
authored andcommitted
Add didyoumean (#31)
* Add didyoumean * Add comment * Fix style issues * Implement like in linked comment
1 parent 0fbe213 commit d10bc1c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Diff for: bin/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const chalk = require('chalk');
66
const program = require('commander');
7+
const didYouMean = require('didyoumean');
78

89
const { version } = require('../package');
910

@@ -44,11 +45,22 @@ program
4445
.description('Shows all commands available')
4546
.action(showCommands);
4647

48+
const suggestCommands = cmd => {
49+
const availableCommands = program.commands.map(c => c._name);
50+
51+
// Get a suggestion from didyoumean.js based on the input.
52+
const suggestion = didYouMean(cmd, availableCommands);
53+
if (suggestion) {
54+
console.log(` ` + chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`));
55+
}
56+
};
57+
4758
// Validates any random command fired in
4859
program.arguments('<command>').action(cmd => {
4960
program.outputHelp();
5061
console.log(` ` + chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`));
5162
console.log();
63+
suggestCommands(cmd);
5264
});
5365

5466
program.parse(process.argv);

Diff for: package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"chalk": "^2.4.1",
4747
"cli-table3": "^0.5.1",
4848
"commander": "^2.18.0",
49+
"didyoumean": "^1.2.1",
4950
"execa": "^1.0.0",
5051
"inquirer": "^6.2.0",
5152
"node-banner": "^1.3.2",

0 commit comments

Comments
 (0)