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

Add didyoumean #31

Merged
merged 4 commits into from
Oct 7, 2019
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
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 @@ -41,11 +42,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