"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const command_base_tenantless_1 = require("../command-base-tenantless");
class Dep extends command_base_tenantless_1.CommandBaseTenantless {
    run() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
                try {
                    this.bootstrap();
                    const { args, flags } = yield this.parse(Dep);
                    let dep = "";
                    let version = flags.version;
                    if (!args.name) {
                        throw new Error(`No dependency specified; you must pass in name of the dependency to install.  No work was done.`);
                    }
                    else {
                        dep = args.name;
                        if ((dep).indexOf("@") > 0) {
                            if (flags.version && flags.version != dep.split("@")[1]) {
                                throw new Error(`Conflicting versions specified: the version suffix on (${args.name}) versus the -v|--version parameter (${flags.version}). No work was done.`);
                            }
                            else {
                                version = dep.split("@")[1];
                            }
                            dep = dep.split("@")[0];
                        }
                        yield this._ops.dependencyInstall(dep, version);
                        this._ui.userMessage(`COMPLETED! Successfully installed dependency: ${dep} version ${version}`);
                    }
                    resolve();
                }
                catch (err) {
                    this.handleError(err);
                    reject(err);
                }
            }));
        });
    }
}
exports.default = Dep;
Dep.description = 'Installs a package into current project.';
Dep.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    version: core_1.Flags.string({ char: 'v', description: 'version of the package to install' })
};
Dep.args = {
    name: core_1.Args.string({ description: 'The official unique name of the package to install.' })
};
//# sourceMappingURL=dep.js.map