"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkIsWizCliCommand = void 0;
const Logger_1 = require("../modules/Logger");
const levenshtien = require("damerau-levenshtein");
const ramda_1 = require("ramda");
const WIZ_COMMAND = process.argv[2] || '';
function checkIsWizCliCommand(commander) {
    if (isWizCliCommand(commander)) {
        commander.parse(process.argv);
    }
    else {
        const commandNames = commander.commands.reduce((acc, cmd) => [...acc, cmd.name()], ['help', 'version']);
        const similarityCmds = commandNames.map(cmd => {
            return {
                cmd,
                match: levenshtien(WIZ_COMMAND, cmd),
            };
        });
        const [matches] = ramda_1.sort(ramda_1.descend(ramda_1.path(['match', 'similarity'])), similarityCmds);
        if (matches.match.similarity) {
            Logger_1.default.warn(`This command doesn't exist. Did you mean 'wiz ${matches.cmd}'? Run 'wiz --help' for the full list of commands.`);
        }
        else {
            Logger_1.default.warn("wiz %s, is not a wiz-cli command. See 'wiz --help'", WIZ_COMMAND);
        }
    }
}
exports.checkIsWizCliCommand = checkIsWizCliCommand;
function isWizCliCommand(commander) {
    return commander.commands.find((cmd) => {
        const isCurrentCommand = cmd.name() === WIZ_COMMAND;
        const isCurrentAlias = cmd.aliases().includes(WIZ_COMMAND);
        const commandIsHelp = WIZ_COMMAND === '--help' || WIZ_COMMAND === '-h';
        const commandIsVersion = WIZ_COMMAND === '--version' || WIZ_COMMAND === '-V';
        const isWizCliCommand = isCurrentAlias || commandIsHelp || commandIsVersion || isCurrentCommand;
        return isWizCliCommand;
    });
}
//# sourceMappingURL=isWizCliCommand.js.map