"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const inquirer = require("inquirer");
const command_base_tenantless_1 = require("../../command-base-tenantless");
class DepSyncup 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(DepSyncup);
                    let projectRoot = this._ops.getConfigRoot();
                    let dep = args.dependency;
                    // Support version suffixes (eg: my-fav-pkg@3.14.5)
                    let depNames = yield this._projCfg.submodules.map(sm => sm.folderName);
                    if (depNames.length > 0) {
                        if (!dep || depNames.indexOf(dep) < 0) {
                            let result = yield inquirer.prompt({ type: 'list', name: 'name', message: 'dependency to sync up into main project:', choices: depNames });
                            if (!result.name) {
                                this._ui.userMessage("Operation cancelled: No work was done.");
                                this.exit(0);
                            }
                            else {
                                dep = result.name;
                            }
                        }
                        // this.logger.notice(`This feature is pending and is not yet available, so ${this._styler.hilite(dep)} will have to be built, checked in, published, and consumed manually.  No work wwas done.`);
                        this._ui.userMessage(`This feature is pending and is not yet available, so ${this._styler.hilite(dep)} will have to be built, checked in, published, and consumed manually.  No work wwas done.`);
                    }
                    else {
                        this.logger.error(`No dependencies to sync because none are currently sourced.`, `Use 'cod dep:source' to source dependency.  No work was done.`);
                        this._ui.userMessage(`No dependencies to sync because none are currently sourced.`);
                    }
                    resolve();
                }
                catch (err) {
                    this.handleError(err);
                    reject(err);
                }
            }));
        });
    }
}
exports.default = DepSyncup;
DepSyncup.description = 'Publishes the dependency in its current state and upgrades to it in the main project.';
DepSyncup.flags = {
    help: core_1.Flags.help({ char: 'h' }),
};
DepSyncup.args = {
    dependency: core_1.Args.string({ description: 'The package name of the dependency to sync up into the main project', required: true })
};
//# sourceMappingURL=syncup.js.map