@@ -9,11 +9,11 @@ import ansis from 'ansis';
9
9
import { ux } from '@oclif/core' ;
10
10
import { AnyJson } from '@salesforce/ts-types' ;
11
11
import terminalLink from 'terminal-link' ;
12
- import { printTable , TableOptions } from '@oclif/table' ;
13
- import { env } from '@salesforce/kit' ;
12
+ import { makeTable , printTable , TableOptions } from '@oclif/table' ;
14
13
import { UxBase } from './base.js' ;
15
14
import { Spinner } from './spinner.js' ;
16
15
import styledObject from './styledObject.js' ;
16
+ import { getDefaults } from './table.js' ;
17
17
18
18
/**
19
19
* UX methods for plugins. Automatically suppress console output if outputEnabled is set to false.
@@ -76,54 +76,28 @@ export class Ux extends UxBase {
76
76
* @param options Table properties
77
77
*/
78
78
public table < T extends Record < string , unknown > > ( options : TableOptions < T > ) : void {
79
- const borderStyles = [
80
- 'all' ,
81
- 'headers-only-with-outline' ,
82
- 'headers-only-with-underline' ,
83
- 'headers-only' ,
84
- 'horizontal-with-outline' ,
85
- 'horizontal' ,
86
- 'none' ,
87
- 'outline' ,
88
- 'vertical-with-outline' ,
89
- 'vertical' ,
90
- ] ;
91
-
92
- const defaultStyle = 'vertical-with-outline' ;
93
- const determineBorderStyle = ( ) : TableOptions < T > [ 'borderStyle' ] => {
94
- const envVar = env . getString ( 'SF_TABLE_BORDER_STYLE' , defaultStyle ) ;
95
- if ( borderStyles . includes ( envVar ) ) {
96
- return envVar as TableOptions < T > [ 'borderStyle' ] ;
97
- }
98
-
99
- return defaultStyle ;
100
- } ;
101
-
102
- const overflowOptions = [ 'wrap' , 'truncate' , 'truncate-middle' , 'truncate-start' , 'truncate-end' ] ;
103
- const determineOverflow = ( ) : TableOptions < T > [ 'overflow' ] => {
104
- const envVar = env . getString ( 'SF_TABLE_OVERFLOW' ) ;
105
- if ( envVar && overflowOptions . includes ( envVar ) ) {
106
- return envVar as TableOptions < T > [ 'overflow' ] ;
107
- }
108
-
109
- return options . overflow ;
110
- } ;
111
-
112
79
this . maybeNoop ( ( ) =>
113
80
printTable ( {
114
81
...options ,
115
- // Don't allow anyone to override these properties
116
- borderStyle : determineBorderStyle ( ) ,
117
- noStyle : env . getBoolean ( 'SF_NO_TABLE_STYLE' , false ) ,
118
- headerOptions : {
119
- ...options . headerOptions ,
120
- formatter : 'capitalCase' ,
121
- } ,
122
- overflow : determineOverflow ( ) ,
82
+ ...getDefaults < T > ( options ) ,
123
83
} )
124
84
) ;
125
85
}
126
86
87
+ /**
88
+ * Return a string rendering of a table.
89
+ *
90
+ * @param options Table properties
91
+ * @returns string rendering of a table
92
+ */
93
+ // eslint-disable-next-line class-methods-use-this
94
+ public makeTable < T extends Record < string , unknown > > ( options : TableOptions < T > ) : string {
95
+ return makeTable ( {
96
+ ...options ,
97
+ ...getDefaults < T > ( options ) ,
98
+ } ) ;
99
+ }
100
+
127
101
/**
128
102
* Display a url to the console. This will be automatically suppressed if output is disabled.
129
103
*
0 commit comments