Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
fix: no-truncate:true on tables, matches previous behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Mar 31, 2022
1 parent ae7a746 commit d296dfc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
6 changes: 3 additions & 3 deletions src/sfdxCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -27,7 +27,7 @@ const messages = Messages.load('@salesforce/command', 'command', [

export interface SfdxResult {
data?: AnyJson;
tableColumnData?: TableOptions;
tableColumnData?: TableColumns;
display?: (this: Result) => void;
}

Expand All @@ -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 = {}) {
Expand Down
24 changes: 16 additions & 8 deletions src/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,27 +279,33 @@ 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<OclifTableOptions>
if (isArray(options)) {
if (isArray(columns)) {
const tableColumns: Partial<CliUx.Table.table.Columns<Record<string, unknown>>> = {};
for (const col of options) {
for (const col of columns) {
tableColumns[col] = {
header: col
.split(/(?=[A-Z])|[-_\s]/)
.map((w: string) => w.toUpperCase())
.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);
}
}

Expand Down Expand Up @@ -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<CliUx.Table.table.Options> | string[];
// (allow any because matches oclif)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type TableColumns = CliUx.Table.table.Columns<any> | string[];

/**
* A deprecation configuration type. A typical instance can pass `name`,
Expand Down

0 comments on commit d296dfc

Please sign in to comment.