Skip to content

Commit 2ec2056

Browse files
committed
Fix format in core check update command
1 parent d1ef1de commit 2ec2056

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

features/core-check-update.feature

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,25 @@ Feature: Check for more recent versions
4242
"""
4343
1
4444
"""
45+
46+
Scenario: Check output of check update in different formats (no updates available)
47+
Given a WP install
48+
And I run `wp eval 'set_site_transient( "update_core", false );'`
49+
50+
When I run `wp core check-update`
51+
Then STDOUT should be:
52+
"""
53+
Success: WordPress is at the latest version.
54+
"""
55+
56+
When I run `wp core check-update --format=json`
57+
Then STDOUT should be:
58+
"""
59+
[]
60+
"""
61+
62+
When I run `wp core check-update --format=yaml`
63+
Then STDOUT should be:
64+
"""
65+
---
66+
"""

src/Core_Command.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ class Core_Command extends WP_CLI_Command {
7777
* @subcommand check-update
7878
*/
7979
public function check_update( $_, $assoc_args ) {
80+
$format = Utils\get_flag_value( $assoc_args, 'format', 'table' );
8081

8182
$updates = $this->get_updates( $assoc_args );
82-
if ( $updates ) {
83+
84+
if ( $updates || 'table' !== $format ) {
8385
$updates = array_reverse( $updates );
8486
$formatter = new Formatter(
8587
$assoc_args,
8688
[ 'version', 'update_type', 'package_url' ]
8789
);
8890
$formatter->display_items( $updates );
89-
} elseif ( empty( $assoc_args['format'] ) || 'table' === $assoc_args['format'] ) {
91+
} else {
9092
WP_CLI::success( 'WordPress is at the latest version.' );
9193
}
9294
}

0 commit comments

Comments
 (0)