diff --git a/lib/vorpal.js b/lib/vorpal.js index ecd4c3ea..b85eb8f6 100755 --- a/lib/vorpal.js +++ b/lib/vorpal.js @@ -29,6 +29,7 @@ var os = require('os'); var History = require('./history'); var LocalStorage = require('./local-storage'); var wrap = require('wrap-ansi'); +var leven = require('leven'); /** * Initialize a new `Vorpal` instance. @@ -1057,6 +1058,31 @@ vorpal._commandHelp = function (command) { ['', ' Invalid Command. Showing Help:', ''].join('\n') : ''; + if ('' !== invalidString) { + var catchCmd = false; + for (var i = 0; i < this.commands.length; i++) { + catchCmd = this.commands[i]._catch; + if (catchCmd) { + break; + } + } + + if (! catchCmd) { + var hints = []; + for (var i = 0; i < this.commands.length; i++) { + if (4 > leven(command, this.commands[i]._name)) { + hints.push(this.commands[i]._name); + } + } + + if (0 < hints.length) { + return '\n ' + command + + ' is an invalid command. Maybe you mean:\n\n ' + + hints.join('\n '); + } + } + } + var commandMatch = (matches.length > 0); var commandMatchLength = (commandMatch) ? String(command).trim().split(' ').length + 1 : 1; matches = (matches.length === 0) ? this.commands : matches; diff --git a/package.json b/package.json index 52f7b406..55c7951c 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "chalk": "^1.1.0", "in-publish": "^2.0.0", "inquirer": "0.11.0", + "leven": "^2.0.0", "lodash": "^4.5.1", "log-update": "^1.0.2", "minimist": "^1.2.0",