"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugin_commands_audit_1 = require("@pnpm/plugin-commands-audit");
const plugin_commands_import_1 = require("@pnpm/plugin-commands-import");
const plugin_commands_installation_1 = require("@pnpm/plugin-commands-installation");
const plugin_commands_listing_1 = require("@pnpm/plugin-commands-listing");
const plugin_commands_outdated_1 = require("@pnpm/plugin-commands-outdated");
const plugin_commands_publishing_1 = require("@pnpm/plugin-commands-publishing");
const plugin_commands_rebuild_1 = require("@pnpm/plugin-commands-rebuild");
const plugin_commands_script_runners_1 = require("@pnpm/plugin-commands-script-runners");
const plugin_commands_server_1 = require("@pnpm/plugin-commands-server");
const plugin_commands_store_1 = require("@pnpm/plugin-commands-store");
const help_1 = require("./help");
const installTest = require("./installTest");
const recursive = require("./recursive");
const root = require("./root");
const commands = [
    plugin_commands_installation_1.add,
    plugin_commands_audit_1.audit,
    plugin_commands_script_runners_1.exec,
    plugin_commands_import_1.importCommand,
    plugin_commands_installation_1.install,
    installTest,
    plugin_commands_installation_1.link,
    plugin_commands_listing_1.list,
    plugin_commands_outdated_1.outdated,
    plugin_commands_publishing_1.pack,
    plugin_commands_installation_1.prune,
    plugin_commands_publishing_1.publish,
    plugin_commands_rebuild_1.rebuild,
    recursive,
    plugin_commands_installation_1.remove,
    plugin_commands_script_runners_1.restart,
    root,
    plugin_commands_script_runners_1.run,
    plugin_commands_server_1.server,
    plugin_commands_script_runners_1.start,
    plugin_commands_script_runners_1.stop,
    plugin_commands_store_1.store,
    plugin_commands_script_runners_1.test,
    plugin_commands_installation_1.unlink,
    plugin_commands_installation_1.update,
    plugin_commands_listing_1.why,
];
const handlerByCommandName = {};
const helpByCommandName = {};
const cliOptionsTypesByCommandName = {};
const rcOptionsTypesByCommandName = {};
const aliasToFullName = new Map();
for (let i = 0; i < commands.length; i++) {
    const { cliOptionsTypes, commandNames, handler, help, rcOptionsTypes, } = commands[i];
    if (!commandNames || commandNames.length === 0) {
        throw new Error('The command at index ' + i + " doesn't have command names");
    }
    for (const commandName of commandNames) {
        handlerByCommandName[commandName] = handler;
        helpByCommandName[commandName] = help;
        cliOptionsTypesByCommandName[commandName] = cliOptionsTypes;
        rcOptionsTypesByCommandName[commandName] = rcOptionsTypes;
    }
    if (commandNames.length > 1) {
        const fullName = commandNames[0];
        for (let i = 1; i < commandNames.length; i++) {
            aliasToFullName.set(commandNames[i], fullName);
        }
    }
}
handlerByCommandName.help = help_1.default(helpByCommandName);
exports.default = handlerByCommandName;
function getCliOptionsTypes(commandName) {
    var _a, _b;
    return ((_b = (_a = cliOptionsTypesByCommandName)[commandName]) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
}
exports.getCliOptionsTypes = getCliOptionsTypes;
function getRCOptionsTypes(commandName) {
    var _a, _b;
    return ((_b = (_a = rcOptionsTypesByCommandName)[commandName]) === null || _b === void 0 ? void 0 : _b.call(_a)) || {};
}
exports.getRCOptionsTypes = getRCOptionsTypes;
function getCommandFullName(commandName) {
    return aliasToFullName.get(commandName) || commandName;
}
exports.getCommandFullName = getCommandFullName;
