From 3f34340eaa800ad0019a87599646d6f91529b16f Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 7 Sep 2023 08:17:27 -0500 Subject: [PATCH] fix: show retrieve warnings in a table --- src/formatters/retrieveResultFormatter.ts | 37 +++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/formatters/retrieveResultFormatter.ts b/src/formatters/retrieveResultFormatter.ts index 7a269c92..0b864a58 100644 --- a/src/formatters/retrieveResultFormatter.ts +++ b/src/formatters/retrieveResultFormatter.ts @@ -6,8 +6,9 @@ */ import * as path from 'path'; import { Ux } from '@salesforce/sf-plugins-core'; -import { FileResponse, RetrieveResult } from '@salesforce/source-deploy-retrieve'; +import { FileResponse, RetrieveMessage, RetrieveResult } from '@salesforce/source-deploy-retrieve'; import { NamedPackageDir, SfProject } from '@salesforce/core'; +import { ensureArray } from '@salesforce/kit'; import { Formatter, isSdrSuccess, RetrieveResultJson } from '../utils/types'; import { sortFileResponses, asRelativePaths, tableHeader, getFileResponseSuccessProps } from '../utils/output'; @@ -44,20 +45,28 @@ export class RetrieveResultFormatter implements Formatter { // a retrieve didn't happen, probably because everything was ignored or there were no remote changes to retrieve this.ux.log('Nothing retrieved'); } - return; - } + } else { + const columns = { + state: { header: 'State' }, + fullName: { header: 'Name' }, + type: { header: 'Type' }, + filePath: { header: 'Path' }, + }; + const options = { title: tableHeader('Retrieved Source'), 'no-truncate': true }; + this.ux.log(); - const columns = { - state: { header: 'State' }, - fullName: { header: 'Name' }, - type: { header: 'Type' }, - filePath: { header: 'Path' }, - }; - const title = 'Retrieved Source'; - const options = { title: tableHeader(title), 'no-truncate': true }; - this.ux.log(); + this.ux.table(getFileResponseSuccessProps(successes), columns, options); + } - this.ux.table(getFileResponseSuccessProps(successes), columns, options); + const warnings = getWarnings(this.result); + if (warnings.length) { + this.ux.log(); + this.ux.table( + warnings, + { fileName: { header: 'File' }, problem: { header: 'Problem' } }, + { 'no-truncate': true, title: tableHeader('Warnings') } + ); + } } private async displayPackages(): Promise { @@ -82,3 +91,5 @@ export class RetrieveResultFormatter implements Formatter { }); } } + +const getWarnings = (result: RetrieveResult): RetrieveMessage[] => ensureArray(result?.response?.messages ?? []);