Skip to content

Commit

Permalink
Add format in core update
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Mar 8, 2024
1 parent d1ef1de commit 7b7f36b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Core_Command.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -1064,6 +1065,15 @@ private static function get_core_checksums( $version, $locale, $insecure ) {
* [--locale=<locale>]
* : Select which language you want to download.
*
* [--format=<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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7b7f36b

Please sign in to comment.