1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const color_1 = require("@heroku-cli/color");
|
5 | const cli_ux_1 = require("cli-ux");
|
6 | const base_1 = require("./commands/base");
|
7 | const deps_1 = require("./deps");
|
8 | class NotFound extends base_1.default {
|
9 | run() {
|
10 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
11 | this.cm = new deps_1.default.CommandManager(this.config);
|
12 | let closest;
|
13 | let binHelp = `${this.config.bin} help`;
|
14 | let id = this.argv[0];
|
15 | let idSplit = id.split(':');
|
16 | if (yield this.cm.findTopic(idSplit[0])) {
|
17 |
|
18 | binHelp = `${binHelp} ${idSplit[0]}`;
|
19 |
|
20 | if (idSplit[1])
|
21 | closest = this.closest(id);
|
22 | }
|
23 | else {
|
24 | closest = this.closest(id);
|
25 | }
|
26 | let perhaps = closest ? `Perhaps you meant ${color_1.color.yellow(yield closest)}\n` : '';
|
27 | cli_ux_1.default.error(`${color_1.color.yellow(id)} is not a ${this.config.bin} command.
|
28 | ${perhaps}Run ${color_1.color.cmd(binHelp)} for a list of available commands.`, { exitCode: 127 });
|
29 | });
|
30 | }
|
31 | allCommands() {
|
32 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
33 | let commands = yield this.cm.commands();
|
34 | return commands.map(c => c.id);
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | });
|
40 | }
|
41 | closest(cmd) {
|
42 | return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
43 | const DCE = require('string-similarity');
|
44 | return DCE.findBestMatch(cmd, yield this.allCommands()).bestMatch.target;
|
45 | });
|
46 | }
|
47 | }
|
48 | NotFound.variableArgs = true;
|
49 | exports.default = NotFound;
|