UNPKG

@copado/copado-cli

Version:

Copado Developer CLI

47 lines 2.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@salesforce/core"); const environments_1 = __importDefault(require("../../../selector/environments")); const sf_plugins_core_1 = require("@salesforce/sf-plugins-core"); core_1.Messages.importMessagesDirectory(__dirname); const messages = core_1.Messages.loadMessages('@copado/copado-cli', 'copado_environment'); class ListEnvironment extends sf_plugins_core_1.SfCommand { async run() { const ux = new sf_plugins_core_1.Ux({ jsonEnabled: this.jsonEnabled() }); try { const { flags } = await this.parse(ListEnvironment); ux.spinner.start(messages.getMessage('list.fetching')); const result = (flags.type) ? await new environments_1.default().byType(flags.type) : await new environments_1.default().all(); ux.spinner.stop(); if (!result.length) { throw new core_1.SfError(messages.getMessage('list.noRecord')); } this.showResults(result, flags, ux); return result; } catch (error) { ux.spinner.stop(); throw new core_1.SfError(error.message); } } showResults(records, flags, ux) { const keys = Object.keys(records[0]).filter(attribute => attribute !== 'attributes'); const columns = {}; keys.forEach(key => columns[key] = {}); const header = (flags.type) ? `${flags.type} Environments` : 'All Environments'; ux.styledHeader(header); ux.table(records, columns); } } exports.default = ListEnvironment; ListEnvironment.description = messages.getMessage('list.description'); ListEnvironment.examples = [messages.getMessage('list.example')]; ListEnvironment.flags = { type: sf_plugins_core_1.Flags.string({ char: 't', description: messages.getMessage('list.flags.type') }) }; //# sourceMappingURL=list.js.map