Skip to content

Commit

Permalink
Add didyoumean (#31)
Browse files Browse the repository at this point in the history
* Add didyoumean

* Add comment

* Fix style issues

* Implement like in linked comment
  • Loading branch information
LapinoLapidus authored and jamesgeorge007 committed Oct 7, 2019
1 parent 0fbe213 commit d10bc1c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const chalk = require('chalk');
const program = require('commander');
const didYouMean = require('didyoumean');

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

Expand Down Expand Up @@ -44,11 +45,22 @@ program
.description('Shows all commands available')
.action(showCommands);

const suggestCommands = cmd => {
const availableCommands = program.commands.map(c => c._name);

// Get a suggestion from didyoumean.js based on the input.
const suggestion = didYouMean(cmd, availableCommands);
if (suggestion) {
console.log(` ` + chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`));
}
};

// Validates any random command fired in
program.arguments('<command>').action(cmd => {
program.outputHelp();
console.log(` ` + chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`));
console.log();
suggestCommands(cmd);
});

program.parse(process.argv);
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"chalk": "^2.4.1",
"cli-table3": "^0.5.1",
"commander": "^2.18.0",
"didyoumean": "^1.2.1",
"execa": "^1.0.0",
"inquirer": "^6.2.0",
"node-banner": "^1.3.2",
Expand Down

0 comments on commit d10bc1c

Please sign in to comment.