Skip to content

[ wp core check-update ] - format options parameter #250

Closed

Description

@riccardodicurti

Summary:
From the information contained in the WordPress Developer Resources I read that it can set the return format https://developer.wordpress.org/cli/commands/core/update/ but give a return only for table format.

Steps to reproduce:
Run command ‘wp core check-update --format=json’

` /**
* Checks for WordPress updates via Version Check API.
*
* Lists the most recent versions when there are updates available,
* or success message when up to date.
*
* ## OPTIONS
*
* [--minor]
* : Compare only the first two parts of the version number.
*
* [--major]
* : Compare only the first part of the version number.
*
* [--force-check]
* : Bypass the transient cache and force a fresh update check.
*
* [--field=]
* : Prints the value of a single field for each update.
*
* [--fields=]
* : Limit the output to specific object fields. Defaults to version,update_type,package_url.
*
* [--format=]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - csv
* - count
* - json
* - yaml
* ---
*
* ## EXAMPLES
*
* $ wp core check-update
* +---------+-------------+-------------------------------------------------------------+
* | version | update_type | package_url |
* +---------+-------------+-------------------------------------------------------------+
* | 4.5.2 | major | https://downloads.wordpress.org/release/wordpress-4.5.2.zip |
* +---------+-------------+-------------------------------------------------------------+
*
* @subcommand check-update
*/
public function check_update( $_, $assoc_args ) {

	$updates = $this->get_updates( $assoc_args );
	if ( $updates ) {
		$updates   = array_reverse( $updates );
		$formatter = new Formatter(
			$assoc_args,
			[ 'version', 'update_type', 'package_url' ]
		);
		$formatter->display_items( $updates );
	} elseif ( empty( $assoc_args['format'] ) || 'table' === $assoc_args['format'] ) {
		WP_CLI::success( 'WordPress is at the latest version.' );
	}
}

`

Activity

  1. danielbachhuber commented on Feb 25, 2024

    @danielbachhuber
    Member

    Thanks for the report, @riccardodicurti

    I believe wp core check-update --format=json returns an empty result because there are no updates available.

    What is your expected behavior?

  2. riccardodicurti commented on Feb 25, 2024

    @riccardodicurti
    Author

    Ciao @danielbachhuber
    I would at least expect an empty json or a message telling me that no updates are available.

  3. danielbachhuber commented on Feb 25, 2024

    @danielbachhuber
    Member

    I would at least expect an empty json or a message telling me that no updates are available.

    I'm not sure a message would make sense. If you're passing the data into JSON parser, a string would break the parser.

    wp post list --format=json produces an empty array:

    $ wp post list --format=json
    []
    

    Would an empty array work for your purposes?

    Also, for posterity, could you share a bit more detail about your use case?

  4. riccardodicurti commented on Feb 26, 2024

    @riccardodicurti
    Author

    Yes, my suggestion was definitely to return the message via json. In any case, the empty array is still sufficient to verify that we have received the response.

    I am currently writing a set of tests and update routines via ssh using the cli.

  5. danielbachhuber commented on Feb 26, 2024

    @danielbachhuber
    Member

    Ok, makes sense. I think I'd be fine to change wp core check-update --format=json to return an empty array, and consider this a bug in the original implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions