Skip to content

Commit

Permalink
Revert "fix: export makeTable"
Browse files Browse the repository at this point in the history
This reverts commit 5fb127e.
  • Loading branch information
mdonnalley committed Oct 22, 2024
1 parent 255a0df commit 897e2ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
57 changes: 1 addition & 56 deletions src/ux/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Record<string, unknown>> = {
extended: boolean;
Expand Down Expand Up @@ -57,57 +56,3 @@ export function convertToNewTableAPI<T extends Record<string, unknown>>(

return { data: d, title: options?.title, borderStyle: 'headers-only-with-underline', columns: cols };
}

export function getTableDefaults<T extends Record<string, unknown>>(
options: TableOptions<T>
): Pick<TableOptions<T>, '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<T>['borderStyle'] => {
const envVar = env.getString('SF_TABLE_BORDER_STYLE', defaultStyle);
if (borderStyles.includes(envVar)) {
return envVar as TableOptions<T>['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<T>} options - The options to configure the table.
* @returns {string} The string representation of the table.
*/
export function makeTable<T extends Record<string, unknown>>(options: TableOptions<T>): string {
return oclifMakeTable({
...options,
// Don't allow anyone to override these properties
...getTableDefaults(options),
});
}
32 changes: 30 additions & 2 deletions src/ux/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -76,11 +76,39 @@ export class Ux extends UxBase {
* @param options Table properties
*/
public table<T extends Record<string, unknown>>(options: TableOptions<T>): 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<T>['borderStyle'] => {
const envVar = env.getString('SF_TABLE_BORDER_STYLE', defaultStyle);
if (borderStyles.includes(envVar)) {
return envVar as TableOptions<T>['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',
},
})
);
}
Expand Down

0 comments on commit 897e2ae

Please sign in to comment.