55use WP_CLI \Iterators \Table as TableIterator ;
66use WP_CLI \Utils ;
77use WP_CLI \Formatter ;
8+ use WP_CLI \Loggers ;
89use WP_CLI \WpOrgApi ;
910
1011/**
@@ -1073,6 +1074,15 @@ private static function get_core_checksums( $version, $locale, $insecure ) {
10731074 * [--locale=<locale>]
10741075 * : Select which language you want to download.
10751076 *
1077+ * [--format=<format>]
1078+ * : Render output in a particular format.
1079+ * ---
1080+ * options:
1081+ * - table
1082+ * - csv
1083+ * - json
1084+ * ---
1085+ *
10761086 * [--insecure]
10771087 * : Retry download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
10781088 *
@@ -1104,7 +1114,7 @@ private static function get_core_checksums( $version, $locale, $insecure ) {
11041114 * @alias upgrade
11051115 *
11061116 * @param array{0?: string} $args Positional arguments.
1107- * @param array{minor?: bool, version?: string, force?: bool, locale?: string, insecure?: bool} $assoc_args Associative arguments.
1117+ * @param array{minor?: bool, version?: string, force?: bool, locale?: string, insecure?: bool, format?: string } $assoc_args Associative arguments.
11081118 */
11091119 public function update ( $ args , $ assoc_args ) {
11101120 global $ wp_version ;
@@ -1116,6 +1126,11 @@ public function update( $args, $assoc_args ) {
11161126 $ assoc_args ['version ' ] = 'nightly ' ;
11171127 }
11181128
1129+ if ( ! empty ( $ assoc_args ['format ' ] ) && in_array ( $ assoc_args ['format ' ], [ 'json ' , 'csv ' ], true ) ) {
1130+ $ logger = new Loggers \Quiet ( WP_CLI ::get_runner ()->in_color () );
1131+ WP_CLI ::set_logger ( $ logger );
1132+ }
1133+
11191134 if ( ! empty ( $ args [0 ] ) ) {
11201135
11211136 // ZIP path or URL is given
@@ -1237,6 +1252,21 @@ public function update( $args, $assoc_args ) {
12371252 $ locale = Utils \get_flag_value ( $ assoc_args , 'locale ' , get_locale () );
12381253 $ this ->cleanup_extra_files ( $ from_version , $ to_version , $ locale , $ insecure );
12391254
1255+ $ data = [
1256+ [
1257+ 'name ' => 'core ' ,
1258+ 'old_version ' => $ from_version ,
1259+ 'new_version ' => $ to_version ,
1260+ 'status ' => 'Updated ' ,
1261+ ],
1262+ ];
1263+
1264+ $ format = Utils \get_flag_value ( $ assoc_args , 'format ' );
1265+
1266+ if ( ! empty ( $ format ) ) {
1267+ Utils \format_items ( $ format , $ data , [ 'name ' , 'old_version ' , 'new_version ' , 'status ' ] );
1268+ }
1269+
12401270 WP_CLI ::success ( 'WordPress updated successfully. ' );
12411271 }
12421272 } else {
0 commit comments