feat: recommend matching commands

This commit is contained in:
jamesgeorge007 2020-04-01 11:50:49 +05:30
parent f3e7284f8e
commit e287784228

View file

@ -1,5 +1,5 @@
import * as program from 'commander';
import * as didYouMean from 'didyoumean';
import * as leven from 'leven';
import { packageCommand, ls } from './package';
import { publish, unpublish } from './publish';
@ -138,7 +138,9 @@ module.exports = function (argv: string[]): void {
.command('*', '', { noHelp: true })
.action((cmd: string) => {
program.help(help => {
const suggestion = didYouMean(cmd, program.commands.map(c => c._name));
const suggestion = program.commands.map(c => c._name).find(c => {
return leven(c, cmd) < c.length * 0.4;
});
help = `${help}
Unknown command '${cmd}'`;