"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 Switch 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(Switch);
                    let branch;
                    let branches = yield this._ops.gitListBranches(true, true);
                    // throw new Error("Operation cancelled: You must specify the name of the branch to create.  No work was done.");
                    if (args.name && branches.indexOf(args.name) >= 0) {
                        branch = args.name;
                    }
                    else {
                        // let result = await inquirer.prompt({ type: 'list', name: 'name', message: 'branch to switch to: (ctrl-c to cancel) ', choices: branches });
                        branch = (yield this._ui.promptSelect("name", 'branch to switch to: (ctrl-c to cancel) ', branches));
                    }
                    yield this._ops.gitSwitchToBranch(branch);
                    resolve();
                }
                catch (err) {
                    this.handleError(err);
                    reject(err);
                }
            }));
        });
    }
}
exports.default = Switch;
Switch.description = 'Changes branch on the main project and any sourced dependencies.';
Switch.flags = {
    help: core_1.Flags.help({ char: 'h' })
};
Switch.args = {
    name: core_1.Args.string({ description: 'The name of the branch to switch to (Optional: will prompt the user when missing).' })
};
//# sourceMappingURL=switch.js.map