diff --git a/src/exported.ts b/src/exported.ts index 9f668e0..1074a55 100644 --- a/src/exported.ts +++ b/src/exported.ts @@ -7,6 +7,6 @@ import { Result, SfdxCommand, SfdxResult } from './sfdxCommand'; import { flags, FlagsConfig } from './sfdxFlags'; -import { TableOptions, UX } from './ux'; +import { TableColumns, UX } from './ux'; -export { Result, SfdxCommand, SfdxResult, FlagsConfig, flags, TableOptions, UX }; +export { Result, SfdxCommand, SfdxResult, FlagsConfig, flags, TableColumns, UX }; diff --git a/src/sfdxCommand.ts b/src/sfdxCommand.ts index bab44e2..955fead 100644 --- a/src/sfdxCommand.ts +++ b/src/sfdxCommand.ts @@ -12,7 +12,7 @@ import chalk from 'chalk'; import { OutputArgs, OutputFlags } from '@oclif/core/lib/interfaces'; import { DocOpts } from './docOpts'; import { buildSfdxFlags, flags as Flags, FlagsConfig } from './sfdxFlags'; -import { Deprecation, DeprecationDefinition, TableOptions, UX } from './ux'; +import { Deprecation, DeprecationDefinition, TableColumns, UX } from './ux'; Messages.importMessagesDirectory(__dirname); const messages = Messages.load('@salesforce/command', 'command', [ @@ -27,7 +27,7 @@ const messages = Messages.load('@salesforce/command', 'command', [ export interface SfdxResult { data?: AnyJson; - tableColumnData?: TableOptions; + tableColumnData?: TableColumns; display?: (this: Result) => void; } @@ -39,7 +39,7 @@ export interface SfdxResult { */ export class Result implements SfdxResult { public data!: AnyJson; // assigned in SfdxCommand._run - public tableColumnData?: TableOptions; + public tableColumnData?: TableColumns; public ux!: UX; // assigned in SfdxCommand.init public constructor(config: SfdxResult = {}) { diff --git a/src/ux.ts b/src/ux.ts index f6d98af..197b8f3 100644 --- a/src/ux.ts +++ b/src/ux.ts @@ -279,17 +279,23 @@ export class UX { * stream output is enabled. * * @param {object[]} rows The rows of data to be output in table format. + * @param columns Table column options * @param {SfdxTableOptions} options The {@link SfdxTableOptions} to use for formatting. * @returns {UX} */ - // (allow any because matches oclif) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public table(rows: any[], options: TableOptions = {}): UX { + + public table( + // (allow any because matches oclif) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + rows: any[], + columns: TableColumns = {}, + options: CliUx.Table.table.Options = { 'no-truncate': true } + ): UX { if (this.isOutputEnabled) { // This is either an array of column names or an already built Partial - if (isArray(options)) { + if (isArray(columns)) { const tableColumns: Partial>> = {}; - for (const col of options) { + for (const col of columns) { tableColumns[col] = { header: col .split(/(?=[A-Z])|[-_\s]/) @@ -297,9 +303,9 @@ export class UX { .join(' '), }; } - this.cli.ux.table(rows, { columns: tableColumns }); + this.cli.ux.table(rows, { columns: tableColumns }, options); } else { - this.cli.ux.table(rows, options); + this.cli.ux.table(rows, columns, options); } } @@ -361,7 +367,9 @@ export class UX { * more simply just a string array in the simple cases where table header values * are the only desired config option. */ -export type TableOptions = Partial | string[]; +// (allow any because matches oclif) +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type TableColumns = CliUx.Table.table.Columns | string[]; /** * A deprecation configuration type. A typical instance can pass `name`,