"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 ImagesVersion extends command_base_tenantless_1.CommandBaseTenantless {
    run() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.bootstrap();
            const { args, flags } = yield this.parse(ImagesVersion);
            const foundImage = this._projCfg.images[args.name];
            if (foundImage) {
                // this._ui.userMessage(JSON.stringify(this._projCfg.images));
                if (flags.output == "json") {
                    this._ui.userMessage(JSON.stringify(foundImage.version, undefined, 2));
                }
                else {
                    // if (flags.output != "csv") {
                    //   this._ui.userMessage(`ImageExports in ${utils.inOrange(this._projCfg.name)}:`);
                    // }
                    console.log(foundImage.version);
                }
            }
            else {
                this._ui.userMessage(`No images are configured as an exports in this project.`);
            }
        });
    }
    getDefaultRegistry(image) {
        let target;
        if (image.targets && image.targets.length > 0) {
            let def = image.targets.find(t => t.environment == "default");
            target = def || image.targets[0];
        }
        return target;
    }
    getDefaultRegistryUrl(image) {
        let output;
        let target = this.getDefaultRegistry(image);
        if (target) {
            let prefix = (image.targets.length > 1) ? `(${target.environment}) ` : "";
            output = `${prefix}${target.registryUrl}`;
        }
        return output;
    }
    getDefaultRegistryInfoUrl(image) {
        let output;
        let target = this.getDefaultRegistry(image);
        if (target) {
            output = target.infoUrl;
        }
        return output;
    }
}
exports.default = ImagesVersion;
ImagesVersion.description = 'Output the local version a given image. useful for ci/cd automation.';
ImagesVersion.aliases = ["image:version:get", "img:version:get"];
ImagesVersion.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    output: core_1.Flags.string({ char: 'o', options: ['stdOut', 'json'], default: 'stdOut', description: "Format for the response data." })
};
ImagesVersion.args = {
    name: core_1.Args.string({ description: "Image name", required: true })
};
//# sourceMappingURL=version.js.map