liveperson-functions-cli
Version:
LivePerson Functions CLI
50 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.commandNotFound = void 0;
/* eslint-disable no-console */
const color_1 = require("@oclif/color");
const Levenshtein = require("fast-levenshtein");
const _ = require("lodash");
/**
* Prints a warning to the user if the command is not found.
* Copy of the plugin-not-found with little adjustments (Plugin doesn't work anymore)
* {@link https://github.com/oclif/plugin-not-found}
* @example output for lpf logi
* Warning: logi is not a lpf command.
* Suggestion: login
* Run lpf help for a list of available commands.
* @export
* @param {*} opts - oclif config
* @returns {Promise<void>}
*/
async function commandNotFound(opts) {
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 binHelp = `${opts.config.bin} help`;
const suggestion = closest(opts.id);
console.log(`Warning: ${color_1.color.yellow(opts.id)} is not a ${opts.config.bin} command.
Suggestion: ${color_1.color.blueBright(suggestion)}
Run ${color_1.color.cmd(binHelp)} for a list of available commands.`);
}
exports.commandNotFound = commandNotFound;
/**
* Runs the a hook every time the CLI cannot found a command
* @param { opts } - oclif configuration
*/
/* istanbul ignore next */
const hook = async function commandNotFoundHook(opts) {
// need to separate the function for the test,
// because there is no context for the command_not_found during the test
/* istanbul ignore next */
await commandNotFound(opts);
/* istanbul ignore next */
this.exit(0);
};
exports.default = hook;
//# sourceMappingURL=commandNotFound.js.map