@@ -19,6 +19,7 @@ type Options = {
1919 businessUnitKey ?: string ;
2020 dynamicToolLoadingThreshold ?: number ;
2121 logging ?: boolean ;
22+ toolOutputFormat ?: 'json' | 'tabular' ;
2223} ;
2324
2425type EnvVars = {
@@ -47,6 +48,7 @@ const PUBLIC_ARGS = [
4748 'projectKey' ,
4849 'apiUrl' ,
4950 'dynamicToolLoadingThreshold' ,
51+ 'toolOutputFormat' ,
5052] ;
5153
5254const ACCEPTED_ARGS = [ ...PUBLIC_ARGS , ...HIDDEN_ARGS ] ;
@@ -176,6 +178,7 @@ export function parseArgs(args: string[]): {options: Options; env: EnvVars} {
176178 const options : Options = { } ;
177179 const env : EnvVars = { } ;
178180
181+ // eslint-disable-next-line complexity
179182 args . forEach ( ( arg ) => {
180183 if ( arg . startsWith ( '--' ) ) {
181184 const [ key , value ] = arg . slice ( 2 ) . split ( '=' ) ;
@@ -208,6 +211,10 @@ export function parseArgs(args: string[]): {options: Options; env: EnvVars} {
208211 options . isAdmin = value === 'true' ;
209212 } else if ( key == 'dynamicToolLoadingThreshold' ) {
210213 options . dynamicToolLoadingThreshold = Number ( value ) ;
214+ } else if ( key == 'toolOutputFormat' ) {
215+ if ( value === 'json' || value === 'tabular' ) {
216+ options . toolOutputFormat = value ;
217+ }
211218 } else if ( key == 'logging' ) {
212219 options . logging = value == 'true' ;
213220 } else if ( key == 'cartId' ) {
@@ -276,6 +283,15 @@ export function parseArgs(args: string[]): {options: Options; env: EnvVars} {
276283 ( process . env . DYNAMIC_TOOL_LOADING_THRESHOLD
277284 ? Number ( process . env . DYNAMIC_TOOL_LOADING_THRESHOLD )
278285 : undefined ) ;
286+
287+ if (
288+ ( process . env . TOOL_OUTPUT_FORMAT &&
289+ process . env . TOOL_OUTPUT_FORMAT === 'tabular' ) ||
290+ process . env . TOOL_OUTPUT_FORMAT === 'json'
291+ ) {
292+ options . toolOutputFormat = process . env . TOOL_OUTPUT_FORMAT ;
293+ }
294+
279295 options . cartId = options . cartId || process . env . CART_ID ;
280296
281297 // Validate required commercetools credentials based on auth type
@@ -357,6 +373,7 @@ export async function main() {
357373 customerId : options . customerId ,
358374 isAdmin : options . isAdmin ,
359375 dynamicToolLoadingThreshold : options . dynamicToolLoadingThreshold ,
376+ toolOutputFormat : options . toolOutputFormat ,
360377 cartId : options . cartId ,
361378 storeKey : options . storeKey ,
362379 businessUnitKey : options . businessUnitKey ,
0 commit comments