"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 Unstage 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(Unstage);
                    let skip = false;
                    let files;
                    if (!args.files && !flags.all) {
                        // throw new Error("Operation cancelled: You must either specify files or set the 'all' flag (--all or -A).");
                        let unstaged = yield this._ops.gitListChanges("staged");
                        if (unstaged.length > 0) {
                            let result = yield inquirer.prompt({
                                type: 'checkbox',
                                name: 'files',
                                message: 'Changes to unstage: (ctrl-c to cancel) ',
                                choices: unstaged
                            });
                            files = result.files;
                        }
                        else {
                            this._ui.userMessage("Nothing to unstage.");
                            skip = true;
                        }
                    }
                    else {
                        // NOTE:  We're gonna leave it to git to validate the given file list
                        files = (args.files) ? args.files.split(" ") : undefined;
                    }
                    if (!skip)
                        yield this._ops.gitUnstage(files);
                    resolve();
                }
                catch (err) {
                    this.handleError(err);
                    reject(err);
                }
            }));
        });
    }
}
exports.default = Unstage;
Unstage.description = 'Flags files to be included in the next commit.';
Unstage.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    all: core_1.Flags.boolean({ char: 'A', description: 'Include all modified files.' })
};
Unstage.args = {
    files: core_1.Args.string({ description: 'Space-separated list of files to stage. Paths are relative to the main project root.', require: false })
};
//# sourceMappingURL=unstage.js.map