UNPKG

@copado/copado-cli

Version:

Copado Developer CLI

51 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@salesforce/core"); const filesystem_1 = require("../../../copado_commons/filesystem"); const listViews_1 = require("../../../service/listViews"); 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_work'); class WorkList extends sf_plugins_core_1.SfCommand { async run() { const copadoConfig = (await filesystem_1.CopadoFiles.getUserConfig()).get('config'); let defaultListView = copadoConfig.defaultlistview === `${filesystem_1.COPADO_NAMESPACE}Cli_Listview` ? 'Cli Listview' : copadoConfig.defaultlistview; const { flags } = await this.parse(WorkList); const listViewToDisplay = flags.listview ? flags.listview : defaultListView; const resRecords = await listViews_1.ListViews.getRecords(listViewToDisplay); let columns = {}; let columnMap = this.getColumns(resRecords); columnMap === null || columnMap === void 0 ? void 0 : columnMap.forEach(key => columns[key] = {}); let records = this.getRecords(resRecords, columnMap); const ux = new sf_plugins_core_1.Ux({ jsonEnabled: this.jsonEnabled() }); ux.styledHeader(listViewToDisplay); ux.table(records, columns); return records; } getColumns(resRecords) { const result = new Map(); // Note : Columns for listview results. Filters are for fields that comes in json but not selected in the SFDC UI. for (const value of resRecords['columns'].filter(col => col['ascendingLabel'] && col['descendingLabel'])) { result.set(value['fieldNameOrPath'], value['label']); } return result; } getRecords(resRecords, columns) { const result = []; for (const recordValue of Object.values(resRecords['records'])) { let line = {}; for (const recResult of Object.values(recordValue['columns']).filter(col => columns.has(col['fieldNameOrPath']))) { line[columns.get(recResult['fieldNameOrPath'])] = recResult['value']; } result.push(line); } return result; } } WorkList.description = messages.getMessage('listCommandDescription'); WorkList.examples = [messages.getMessage('workListExampleDescription')]; WorkList.flags = { listview: sf_plugins_core_1.Flags.string({ char: 'l', description: 'validateFlagDescription' }) }; exports.default = WorkList; //# sourceMappingURL=list.js.map