1313
1414use WP_CLI ;
1515use DataMachine \Cli \BaseCommand ;
16+ use DataMachineCode \Cli \CliResponseRenderer ;
1617use DataMachineCode \Abilities \GitHubAbilities ;
1718use DataMachineCode \GitHub \PrReviewFlowInstaller ;
1819use DataMachineCode \GitHub \PrReviewFlowScaffold ;
@@ -86,7 +87,7 @@ public function issues( array $args, array $assoc_args ): void {
8687 $ format = $ assoc_args ['format ' ] ?? 'table ' ;
8788
8889 if ( 'json ' === $ format ) {
89- WP_CLI :: line ( ( string ) \wp_json_encode ($ result, JSON_PRETTY_PRINT ) );
90+ $ this -> renderer ()-> json ($ result );
9091 return ;
9192 }
9293
@@ -110,7 +111,7 @@ public function issues( array $args, array $assoc_args ): void {
110111 );
111112 }
112113
113- $ this ->format_items ($ items , array ( 'number ' , 'state ' , 'title ' , 'labels ' , 'comments ' , 'created_at ' ), $ assoc_args );
114+ $ this ->renderer ()-> items ($ items , array ( 'number ' , 'state ' , 'title ' , 'labels ' , 'comments ' , 'created_at ' ), $ assoc_args );
114115 WP_CLI ::log (sprintf ('%d issue(s) returned. ' , count ($ items )));
115116 }
116117
@@ -163,7 +164,7 @@ public function view( array $args, array $assoc_args ): void {
163164 $ format = $ assoc_args ['format ' ] ?? 'table ' ;
164165
165166 if ( 'json ' === $ format ) {
166- WP_CLI :: line ( ( string ) \wp_json_encode ($ result, JSON_PRETTY_PRINT ) );
167+ $ this -> renderer ()-> json ($ result );
167168 return ;
168169 }
169170
@@ -351,7 +352,7 @@ public function pulls( array $args, array $assoc_args ): void {
351352 $ format = $ assoc_args ['format ' ] ?? 'table ' ;
352353
353354 if ( 'json ' === $ format ) {
354- WP_CLI :: line ( ( string ) \wp_json_encode ($ result, JSON_PRETTY_PRINT ) );
355+ $ this -> renderer ()-> json ($ result );
355356 return ;
356357 }
357358
@@ -381,7 +382,7 @@ public function pulls( array $args, array $assoc_args ): void {
381382 );
382383 }
383384
384- $ this ->format_items ($ items , array ( 'number ' , 'status ' , 'title ' , 'branch ' , 'user ' , 'created_at ' ), $ assoc_args );
385+ $ this ->renderer ()-> items ($ items , array ( 'number ' , 'status ' , 'title ' , 'branch ' , 'user ' , 'created_at ' ), $ assoc_args );
385386 WP_CLI ::log (sprintf ('%d PR(s) returned. ' , count ($ items )));
386387 }
387388
@@ -568,7 +569,7 @@ public function repos( array $args, array $assoc_args ): void {
568569 $ format = $ assoc_args ['format ' ] ?? 'table ' ;
569570
570571 if ( 'json ' === $ format ) {
571- WP_CLI :: line ( ( string ) \wp_json_encode ($ result, JSON_PRETTY_PRINT ) );
572+ $ this -> renderer ()-> json ($ result );
572573 return ;
573574 }
574575
@@ -591,10 +592,14 @@ public function repos( array $args, array $assoc_args ): void {
591592 );
592593 }
593594
594- $ this ->format_items ($ items , array ( 'repo ' , 'language ' , 'stars ' , 'open_issues ' , 'private ' , 'last_push ' ), $ assoc_args );
595+ $ this ->renderer ()-> items ($ items , array ( 'repo ' , 'language ' , 'stars ' , 'open_issues ' , 'private ' , 'last_push ' ), $ assoc_args );
595596 WP_CLI ::log (sprintf ('%d repo(s) returned. ' , count ($ items )));
596597 }
597598
599+ private function renderer (): CliResponseRenderer {
600+ return new CliResponseRenderer ();
601+ }
602+
598603 /**
599604 * Check GitHub integration status.
600605 *
0 commit comments