diff --git a/src/exported.ts b/src/exported.ts index 99619dfd..cb711af0 100644 --- a/src/exported.ts +++ b/src/exported.ts @@ -9,7 +9,7 @@ export { toHelpSection, parseVarArgs } from './util.js'; export { Progress } from './ux/progress.js'; export { Spinner } from './ux/spinner.js'; export { Ux } from './ux/ux.js'; -export { convertToNewTableAPI, makeTable } from './ux/table.js'; +export { convertToNewTableAPI } from './ux/table.js'; export { StandardColors } from './ux/standardColors.js'; export { SfCommand, SfCommandInterface } from './sfCommand.js'; diff --git a/src/ux/table.ts b/src/ux/table.ts index c4e4791b..c7790819 100644 --- a/src/ux/table.ts +++ b/src/ux/table.ts @@ -4,8 +4,7 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -import { makeTable as oclifMakeTable, TableOptions } from '@oclif/table'; -import { env } from '@salesforce/kit'; +import { TableOptions } from '@oclif/table'; type Column> = { extended: boolean; @@ -57,57 +56,3 @@ export function convertToNewTableAPI>( return { data: d, title: options?.title, borderStyle: 'headers-only-with-underline', columns: cols }; } - -export function getTableDefaults>( - options: TableOptions -): Pick, 'borderStyle' | 'noStyle' | 'headerOptions'> { - const borderStyles = [ - 'all', - 'headers-only-with-outline', - 'headers-only-with-underline', - 'headers-only', - 'horizontal-with-outline', - 'horizontal', - 'none', - 'outline', - 'vertical-with-outline', - 'vertical', - ]; - - const defaultStyle = 'vertical-with-outline'; - const determineBorderStyle = (): TableOptions['borderStyle'] => { - const envVar = env.getString('SF_TABLE_BORDER_STYLE', defaultStyle); - if (borderStyles.includes(envVar)) { - return envVar as TableOptions['borderStyle']; - } - - return defaultStyle; - }; - - return { - borderStyle: determineBorderStyle(), - noStyle: env.getBoolean('SF_NO_TABLE_STYLE', false), - headerOptions: { - ...options.headerOptions, - formatter: 'capitalCase', - }, - }; -} - -/** - * Generates a string representation of a table from the given options. - * - * Consumers should prefer to use the `table` method on the `Ux` class since that will - * respond appropriately to the presence of the `--json` flag. - * - * @template T - The type of the records in the table. - * @param {TableOptions} options - The options to configure the table. - * @returns {string} The string representation of the table. - */ -export function makeTable>(options: TableOptions): string { - return oclifMakeTable({ - ...options, - // Don't allow anyone to override these properties - ...getTableDefaults(options), - }); -} diff --git a/src/ux/ux.ts b/src/ux/ux.ts index a6ddb307..7abca9f7 100644 --- a/src/ux/ux.ts +++ b/src/ux/ux.ts @@ -10,10 +10,10 @@ import { ux } from '@oclif/core'; import { AnyJson } from '@salesforce/ts-types'; import terminalLink from 'terminal-link'; import { printTable, TableOptions } from '@oclif/table'; +import { env } from '@salesforce/kit'; import { UxBase } from './base.js'; import { Spinner } from './spinner.js'; import styledObject from './styledObject.js'; -import { getTableDefaults } from './table.js'; /** * UX methods for plugins. Automatically suppress console output if outputEnabled is set to false. @@ -76,11 +76,39 @@ export class Ux extends UxBase { * @param options Table properties */ public table>(options: TableOptions): void { + const borderStyles = [ + 'all', + 'headers-only-with-outline', + 'headers-only-with-underline', + 'headers-only', + 'horizontal-with-outline', + 'horizontal', + 'none', + 'outline', + 'vertical-with-outline', + 'vertical', + ]; + + const defaultStyle = 'vertical-with-outline'; + const determineBorderStyle = (): TableOptions['borderStyle'] => { + const envVar = env.getString('SF_TABLE_BORDER_STYLE', defaultStyle); + if (borderStyles.includes(envVar)) { + return envVar as TableOptions['borderStyle']; + } + + return defaultStyle; + }; + this.maybeNoop(() => printTable({ ...options, // Don't allow anyone to override these properties - ...getTableDefaults(options), + borderStyle: determineBorderStyle(), + noStyle: env.getBoolean('SF_NO_TABLE_STYLE', false), + headerOptions: { + ...options.headerOptions, + formatter: 'capitalCase', + }, }) ); }