UNPKG

balena-cli

Version:

The official balena Command Line Interface

35 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lazy_1 = require("../../utils/lazy"); const hook = async function (opts) { var _a, _b; const Levenshtein = await Promise.resolve().then(() => require('fast-levenshtein')); const _ = await Promise.resolve().then(() => require('lodash')); const chalk = (0, lazy_1.getChalk)(); const commandId = opts.id || ''; const command = ((_a = opts.id) === null || _a === void 0 ? void 0 : _a.replace(':', ' ')) || ''; const commandIDs = [ ...opts.config.commandIDs, ..._.flatten(opts.config.commands.map((c) => c.aliases)), 'version', ]; function closest(cmd) { return _.minBy(commandIDs, (c) => Levenshtein.get(cmd, c)); } const suggestions = []; suggestions.push(closest(commandId).replace(':', ' ') || ''); if ((_b = opts.argv) === null || _b === void 0 ? void 0 : _b[0]) { suggestions.unshift(closest(`${commandId}: + ${opts.argv[0]}`).replace(':', ' ') || ''); } console.error(`${chalk.yellow(command)} is not a recognized balena command.\n`); console.error(`Did you mean: ? `); suggestions.forEach((s) => { console.error(` ${chalk.cyan.bold(s)}`); }); console.error(`\nRun ${chalk.cyan.bold('balena help -v')} for a list of available commands,`); console.error(` or ${chalk.cyan.bold('balena help <command>')} for detailed help on a specific command.`); const COMMAND_NOT_FOUND = 127; process.exit(COMMAND_NOT_FOUND); }; exports.default = hook; //# sourceMappingURL=suggest.js.map