feat: recommend matching commands
This commit is contained in:
parent
f3e7284f8e
commit
e287784228
1 changed files with 4 additions and 2 deletions
|
@ -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}'`;
|
||||
|
|
Loading…
Add table
Reference in a new issue