Skip to content

Commit 7b7f36b

Browse files
committed
Add format in core update
1 parent d1ef1de commit 7b7f36b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Core_Command.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use WP_CLI\Iterators\Table as TableIterator;
66
use WP_CLI\Utils;
77
use WP_CLI\Formatter;
8+
use WP_CLI\Loggers;
89
use WP_CLI\WpOrgApi;
910

1011
/**
@@ -1064,6 +1065,15 @@ private static function get_core_checksums( $version, $locale, $insecure ) {
10641065
* [--locale=<locale>]
10651066
* : Select which language you want to download.
10661067
*
1068+
* [--format=<format>]
1069+
* : Render output in a particular format.
1070+
* ---
1071+
* options:
1072+
* - table
1073+
* - csv
1074+
* - json
1075+
* ---
1076+
*
10671077
* [--insecure]
10681078
* : Retry download without certificate validation if TLS handshake fails. Note: This makes the request vulnerable to a MITM attack.
10691079
*
@@ -1109,6 +1119,11 @@ public function update( $args, $assoc_args ) {
11091119
$assoc_args['version'] = 'nightly';
11101120
}
11111121

1122+
if ( ! empty( $assoc_args['format'] ) && in_array( $assoc_args['format'], [ 'json', 'csv' ], true ) ) {
1123+
$logger = new Loggers\Quiet( WP_CLI::get_runner()->in_color() );
1124+
WP_CLI::set_logger( $logger );
1125+
}
1126+
11121127
if ( ! empty( $args[0] ) ) {
11131128

11141129
// ZIP path or URL is given
@@ -1214,6 +1229,21 @@ public function update( $args, $assoc_args ) {
12141229
$locale = (string) Utils\get_flag_value( $assoc_args, 'locale', get_locale() );
12151230
$this->cleanup_extra_files( $from_version, $to_version, $locale, $insecure );
12161231

1232+
$data = [
1233+
[
1234+
'name' => $core,
1235+
'old_version' => $from_version,
1236+
'new_version' => $to_version,
1237+
'status' => 'Updated',
1238+
],
1239+
];
1240+
1241+
$format = Utils\get_flag_value( $assoc_args, 'format' );
1242+
1243+
if ( ! empty( $format ) ) {
1244+
Utils\format_items( $format, $data, [ 'name', 'old_version', 'new_version', 'status' ] );
1245+
}
1246+
12171247
WP_CLI::success( 'WordPress updated successfully.' );
12181248
}
12191249
} else {

0 commit comments

Comments
 (0)