"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const _ = require("lodash");
const core_1 = require("@oclif/core");
const command_base_tenantless_1 = require("../../../command-base-tenantless");
const workspace_versioner_1 = require("../../../ops/workspace-versioner");
class ImagesVersionBump extends command_base_tenantless_1.CommandBaseTenantless {
    run() {
        var _a;
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.bootstrap();
            const { args, flags } = yield this.parse(ImagesVersionBump);
            if (this._projCfg.images == undefined || _.isEmpty(this._projCfg.images)) {
                this._ui.userMessage(`No images are configured as an exports in this project. Use 'cod images add' to declare one.`);
            }
            else {
                const foundImage = this._projCfg.images[args.name];
                if (foundImage == undefined) {
                    this._ui.userMessage(`No image found in this project with that name.`);
                }
                else {
                    let versionBump;
                    if (flags.version || flags.major || flags.minor || flags.patch || flags.prerelease || flags.preid) {
                        versionBump = {
                            fullName: flags.version,
                            major: flags.major,
                            minor: flags.minor,
                            patch: flags.patch,
                            prerelease: flags.prerelease,
                            preId: flags.preid
                        };
                    }
                    else {
                        versionBump = { prerelease: true };
                    }
                    let versioner = this.ioc.get(workspace_versioner_1.WorkspaceVersioner);
                    let modified = yield versioner.incrementImageVersion(foundImage, this._projCfg, versionBump);
                    this._ui.userMessage(`${foundImage.name} set to [${this._styler.hilite((_a = modified.version) !== null && _a !== void 0 ? _a : "")}]`);
                }
            }
        });
    }
}
exports.default = ImagesVersionBump;
ImagesVersionBump.description = 'Output the local version a given image. useful for ci/cd automation.';
ImagesVersionBump.aliases = ["image:version:bump", "img:version:bump"];
ImagesVersionBump.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    version: core_1.Flags.string({ description: 'Overwrites the full version for the build (using Major.Minor.Patch).' }),
    major: core_1.Flags.boolean({ char: 'M', description: 'Increments the version by one Major version number (using Major.Minor.Patch).' }),
    minor: core_1.Flags.boolean({ char: 'm', description: 'Increments the version by one Minor version number (using Major.Minor.Patch).' }),
    patch: core_1.Flags.boolean({ char: 'p', description: 'Increments the version by one Patch version number (using Major.Minor.Patch).' }),
    prerelease: core_1.Flags.boolean({ char: 'r', description: '(default for this command) Increments the prerelease number (using Major.Minor.Patch-PreRelease).  NOTE:  Increments the Patch version number when appending.' }),
    preid: core_1.Flags.string({ char: 'i', description: 'Sets the prereleaseId and resets the prerelease number (or increments it if the same preid is already set) (using Major.Minor.Patch-PreId.PreRelease).  NOTE:  Increments the Patch version number when appending.' })
    // silent: Flags.boolean({ char: 'y', description: 'Suppresses user dialogue.', dependsOn: [] })
};
ImagesVersionBump.args = {
    name: core_1.Args.string({ description: "Image name (as it appears in the codiac.json)", required: true })
};
//# sourceMappingURL=bump.js.map