"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander = require("commander");
const uninstall_1 = require("../Api/uninstall");
const I18n_1 = require("../modules/I18n");
const Logger_1 = require("../modules/Logger");
const ensureAuth_1 = require("./utils/ensureAuth");
const logger_1 = require("./utils/logger");
const codeArtifactUtils_1 = require("../utils/codeArtifactUtils");
const ewizardService_types_1 = require("../interfaces/ewizardService.types");
commander
    .name('wiz uninstall')
    .description('wiz uninstall <components...>\n\naliases: rm')
    .addOption(new commander.Option('-r, --repository <repositoryType>').hideHelp())
    .parse(process.argv);
uninstall(commander.args, commander.opts())
    .catch(logger_1.handleError)
    .finally(logger_1.closeLogger);
function uninstall(components = [], options) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!components.length) {
            Logger_1.default.error(I18n_1.default.error('UNRESOLVED_ARGUMENTS'));
            Logger_1.default.info(I18n_1.default.info('UNINSTALL_USAGE_INFO'));
            return;
        }
        const ewizard = yield (0, ensureAuth_1.default)();
        const cwd = process.cwd();
        const npmRegistryParams = yield (0, codeArtifactUtils_1.getNpmRegistryParams)(options, cwd, ewizardService_types_1.ActionType.Install);
        const npmRegistryConfig = yield ewizard.getNpmRegistry(npmRegistryParams);
        const uninstallOptions = Object.assign({ cwd }, npmRegistryConfig);
        const uninstallAction = yield (0, uninstall_1.createAction)(cwd);
        return uninstallAction(components, uninstallOptions);
    });
}
//# sourceMappingURL=wiz-uninstall.js.map