"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 });
exports.PackageManagerCommand = void 0;
const constants_1 = require("../../constants");
const yok_1 = require("../yok");
class PackageManagerCommand {
    constructor($userSettingsService, $errors, $logger, $stringParameter) {
        this.$userSettingsService = $userSettingsService;
        this.$errors = $errors;
        this.$logger = $logger;
        this.$stringParameter = $stringParameter;
        this.allowedParameters = [this.$stringParameter];
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            const packageManagerName = args[0];
            const supportedPackageManagers = Object.keys(constants_1.PackageManagers);
            if (supportedPackageManagers.indexOf(packageManagerName) === -1) {
                this.$errors.fail(`${packageManagerName} is not a valid package manager. Supported values are: ${supportedPackageManagers.join(", ")}.`);
            }
            yield this.$userSettingsService.saveSetting("packageManager", packageManagerName);
            this.$logger.printMarkdown(`Please ensure you have the directory containing \`${packageManagerName}\` executable available in your PATH.`);
            this.$logger.printMarkdown(`You've successfully set \`${packageManagerName}\` as your package manager.`);
        });
    }
}
exports.PackageManagerCommand = PackageManagerCommand;
yok_1.injector.registerCommand("package-manager|set", PackageManagerCommand);
//# sourceMappingURL=package-manager-set.js.map