|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
6 | 6 | */ |
7 | 7 | import os from 'node:os'; |
| 8 | +import { colorize } from '@oclif/core/ux'; |
8 | 9 | import { StatusEvent, ResultEvent, SandboxProcessObject } from '@salesforce/core'; |
9 | | -import { Ux } from '@salesforce/sf-plugins-core'; |
10 | 10 | import { getClockForSeconds } from '../shared/timeUtils.js'; |
11 | 11 | import { StagedProgress } from './stagedProgress.js'; |
12 | 12 | import { isDefined } from './utils.js'; |
13 | 13 |
|
14 | | -const columns: Ux.Table.Columns<{ key: string; value: string }> = { |
15 | | - key: { header: 'Field' }, |
16 | | - value: { header: 'Value' }, |
17 | | -}; |
18 | | - |
19 | | -const ux = new Ux(); |
20 | | - |
21 | 14 | export type SandboxProgressData = { |
22 | 15 | id: string; |
23 | 16 | status: string; |
@@ -73,7 +66,7 @@ export class SandboxProgress extends StagedProgress<SandboxStatusData> { |
73 | 66 | } |
74 | 67 |
|
75 | 68 | public formatProgressStatus(withClock = true): string { |
76 | | - const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj).join(os.EOL); |
| 69 | + const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj); |
77 | 70 | return [ |
78 | 71 | withClock && this.statusData |
79 | 72 | ? `${getClockForSeconds(this.statusData.sandboxProgress.remainingWaitTime)} until timeout. ${ |
@@ -123,15 +116,20 @@ export const getTableDataFromProcessObj = ( |
123 | 116 | ...(authUserName ? [{ key: 'Authorized Sandbox Username', value: authUserName }] : []), |
124 | 117 | ]; |
125 | 118 |
|
126 | | -export const getSandboxTableAsText = (sandboxUsername?: string, sandboxProgress?: SandboxProcessObject): string[] => { |
| 119 | +export const getSandboxTableAsText = (sandboxUsername?: string, sandboxProgress?: SandboxProcessObject): string => { |
127 | 120 | if (!sandboxProgress) { |
128 | | - return []; |
| 121 | + return ''; |
129 | 122 | } |
130 | | - const tableRows: string[] = []; |
131 | | - ux.table(getTableDataFromProcessObj(sandboxProgress, sandboxUsername), columns, { |
132 | | - printLine: (s: string): void => { |
133 | | - tableRows.push(s); |
134 | | - }, |
135 | | - }); |
136 | | - return tableRows; |
| 123 | + |
| 124 | + const data = getTableDataFromProcessObj(sandboxProgress, sandboxUsername); |
| 125 | + const longestKey = data.reduce((acc, row) => (row.key.length > acc ? row.key.length : acc), 0); |
| 126 | + const longestValue = data.reduce( |
| 127 | + (acc, row) => (row.value.toString().length > acc ? row.value.toString().length : acc), |
| 128 | + 0 |
| 129 | + ); |
| 130 | + return [ |
| 131 | + colorize('bold', `${'Field'.padEnd(longestKey)} Value`), |
| 132 | + `${'-'.repeat(longestKey)} ${'-'.repeat(longestValue)}`, |
| 133 | + ...data.map((row) => `${row.key.padEnd(longestKey)} ${row.value}`), |
| 134 | + ].join(os.EOL); |
137 | 135 | }; |
0 commit comments