diff --git a/src/Core_Command.php b/src/Core_Command.php index 80139080..f6412a2b 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -5,6 +5,7 @@ use WP_CLI\Iterators\Table as TableIterator; use WP_CLI\Utils; use WP_CLI\Formatter; +use WP_CLI\Loggers; use WP_CLI\WpOrgApi; /** @@ -1064,6 +1065,15 @@ private static function get_core_checksums( $version, $locale, $insecure ) { * [--locale=] * : Select which language you want to download. * + * [--format=] + * : Render output in a particular format. + * --- + * options: + * - table + * - csv + * - json + * --- + * * [--insecure] * : Retry download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack. * @@ -1109,6 +1119,11 @@ public function update( $args, $assoc_args ) { $assoc_args['version'] = 'nightly'; } + if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], [ 'json', 'csv' ], true ) ) { + $logger = new Loggers\Quiet( WP_CLI::get_runner()->in_color() ); + WP_CLI::set_logger( $logger ); + } + if ( ! empty( $args[0] ) ) { // ZIP path or URL is given @@ -1214,6 +1229,21 @@ public function update( $args, $assoc_args ) { $locale = (string) Utils\get_flag_value( $assoc_args, 'locale', get_locale() ); $this->cleanup_extra_files( $from_version, $to_version, $locale, $insecure ); + $data = [ + [ + 'name' => $core, + 'old_version' => $from_version, + 'new_version' => $to_version, + 'status' => 'Updated', + ], + ]; + + $format = Utils\get_flag_value( $assoc_args, 'format' ); + + if ( ! empty( $format ) ) { + Utils\format_items( $format, $data, [ 'name', 'old_version', 'new_version', 'status' ] ); + } + WP_CLI::success( 'WordPress updated successfully.' ); } } else {