UNPKG

terrac

Version:

A minimal private module registry for Terraform and OpenTofu

74 lines (73 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const Joi = require("joi"); const node_os_1 = require("node:os"); const utils_1 = require("../utils"); const factory_1 = require("../backends/factory"); const requiredConfigSchema = Joi.object({ backend: utils_1.backendConfigSchema.required(), module: utils_1.moduleConfigSchema.optional(), }); class Get extends core_1.Command { async run() { const { args, flags } = await this.parse(Get); const { name, version } = args; const workDir = flags['work-directory']; const config = await (0, utils_1.loadConfig)(workDir, (0, utils_1.parseConfigOverwrites)(flags['overwrite-config'])); await (0, utils_1.validateConfig)(requiredConfigSchema, config); const backend = factory_1.BackendFactory.create(config.backend); const meta = await backend.getMeta(name); const outputVersion = version ? (flags.exact ? (0, utils_1.resolveVersion)(meta, version) : version) : (0, utils_1.resolveVersion)(meta, 'latest'); const sourceUrl = await backend.getSourceUrl(name, outputVersion); if (flags.exact && version !== outputVersion) { this.log(`The input version is resolved to the exact version ${outputVersion} and available at ${sourceUrl}`); } else if (version) { this.log(`The release ${version} is found and available at ${sourceUrl}`); } else { this.log(`The latest release ${outputVersion} is found and available at ${sourceUrl}`); } } } exports.default = Get; Get.description = 'Get the module source URL of the given module and version.'; Get.examples = [ '<%= config.bin %> <%= command.id %> my-module', '<%= config.bin %> <%= command.id %> my-module latest', '<%= config.bin %> <%= command.id %> my-module 1.3.2', '<%= config.bin %> <%= command.id %> my-module 1.3', '<%= config.bin %> <%= command.id %> --exact my-module 1.3', ]; Get.args = { name: core_1.Args.string({ description: 'Module name', required: true, }), version: core_1.Args.string({ description: [ 'Module version. This could be a version name (like latest), a semver, or a semver component.', 'By default, terrac will verify the release with the input version and generate the source URL.', 'If it needs to resolve to an exact version, use the --exact flag.', ].join(node_os_1.EOL), required: false, }), }; Get.flags = { exact: core_1.Flags.boolean({ summary: 'Whether to resolve to an exact version if a named version or a semver component is given', default: false, }), 'work-directory': core_1.Flags.string({ summary: 'Root directory of the module configuration', default: '.', }), 'overwrite-config': core_1.Flags.string({ summary: 'Overwrite terrac configuration', multiple: true, hidden: true, }), };