diff --git a/package.json b/package.json index fd8718ae..b801f2cb 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "cheerio": "^1.0.0-rc.1", "commander": "^2.8.1", "denodeify": "^1.2.1", + "didyoumean": "^1.2.1", "glob": "^7.0.6", "lodash": "^4.17.10", "markdown-it": "^8.3.1", @@ -58,6 +59,7 @@ "@types/cheerio": "^0.22.1", "@types/commander": "^2.12.2", "@types/denodeify": "^1.2.31", + "@types/didyoumean": "^1.2.0", "@types/glob": "^7.1.1", "@types/lodash": "^4.14.123", "@types/markdown-it": "0.0.2", @@ -69,8 +71,8 @@ "@types/semver": "^6.0.0", "@types/tmp": "^0.1.0", "@types/xml2js": "^0.4.4", - "cpx": "^1.5.0", "concurrently": "^4.1.0", + "cpx": "^1.5.0", "mocha": "^5.2.0", "source-map-support": "^0.4.2", "typescript": "^3.4.3", diff --git a/src/main.ts b/src/main.ts index 06326888..5138689e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,6 @@ import * as program from 'commander'; +import * as didYouMean from 'didyoumean'; + import { packageCommand, ls } from './package'; import { publish, unpublish } from './publish'; import { show } from './show'; @@ -127,7 +129,16 @@ module.exports = function (argv: string[]): void { program .command('*') - .action(() => program.help()); + .action((cmd: string) => { + program.outputHelp(); + log.error(`Unknown command ${cmd}`); + + const availableCommands: string[] = program.commands.map(c => c._name); + const suggestion: string | string[] = didYouMean(cmd, availableCommands); + if (suggestion) { + log.warn(`Did you mean '${suggestion}'?`); + } + }); program.parse(argv); diff --git a/yarn.lock b/yarn.lock index c0707e26..3b810cb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -578,6 +578,11 @@ detect-libc@^1.0.2: resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= +didyoumean@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/didyoumean/-/didyoumean-1.2.1.tgz#e92edfdada6537d484d73c0172fd1eba0c4976ff" + integrity sha1-6S7f2tplN9SE1zwBcv0eugxJdv8= + diff@3.5.0: version "3.5.0" resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"