Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,70 @@ There are no optionally available fields.



### wp package get

Gets information about an installed WP-CLI package.

~~~
wp package get <name> [--fields=<fields>] [--format=<format>] [--skip-update-check]
~~~

**OPTIONS**

<name>
Name of the package to get information for.

[--fields=<fields>]
Limit the output to specific fields. Defaults to all fields.

[--format=<format>]
Render output in a particular format.
---
default: table
options:
- table
- csv
- json
- yaml
---

[--skip-update-check]
Skip checking for updates. This is faster and avoids authentication issues with GitHub or Composer repositories.

**AVAILABLE FIELDS**

These fields will be displayed by default for each package:

* name
* authors
* version
* update
* update_version

These fields are optionally available:

* description

**EXAMPLES**

# Get information about an installed package.
$ wp package get wp-cli/scaffold-package-command
+----------------+---------------------------------+
| Field | Value |
+----------------+---------------------------------+
| name | wp-cli/scaffold-package-command |
| authors | Daniel Bachhuber |
| version | dev-main |
| update | available |
| update_version | 2.x-dev |
+----------------+---------------------------------+

# Get the version of a package.
$ wp package get wp-cli/server-command --fields=version --format=json
{"version":"dev-main"}



### wp package install

Installs a WP-CLI package.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"commands": [
"package",
"package browse",
"package get",
"package install",
"package list",
"package update",
Expand Down
66 changes: 66 additions & 0 deletions features/package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,69 @@ Feature: Manage WP-CLI packages

When I run `wp package uninstall runcommand/hook`
Then STDERR should be empty

Scenario: Get information about a single package
Given an empty directory

When I try `wp package get runcommand/hook`
Then STDERR should contain:
"""
Error: Package 'runcommand/hook' is not installed.
"""
And the return code should be 1

When I run `wp package install runcommand/hook`
Then STDERR should be empty

When I run `wp package get runcommand/hook`
Then STDOUT should contain:
"""
runcommand/hook
"""
And STDOUT should contain:
"""
version
"""

When I run `wp package get runcommand/hook --fields=name,version`
Then STDOUT should contain:
"""
runcommand/hook
"""
And STDOUT should contain:
"""
version
"""

When I run `wp package get runcommand/hook --fields=version --format=json`
Then STDOUT should contain:
"""
"version"
"""

When I run `wp package get runcommand/hook --format=json`
Then STDOUT should contain:
"""
"name":"runcommand\/hook"
"""
And STDOUT should contain:
"""
"version"
"""
Comment on lines +235 to +282
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test scenarios should include coverage for the --skip-update-check flag with the package get command, similar to how it's tested for package list. This flag is documented as an available option but is not tested in any scenario.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test coverage for the --skip-update-check flag in commit f1a1b5b. The test verifies that when the flag is used, the update status remains 'none' and doesn't check for available updates.


When I run `wp package get runcommand/hook --skip-update-check --fields=name,update,update_version`
Then STDOUT should contain:
"""
runcommand/hook
"""
And STDOUT should contain:
"""
none
"""
And STDOUT should not contain:
"""
available
"""

When I run `wp package uninstall runcommand/hook`
Then STDERR should be empty
112 changes: 111 additions & 1 deletion src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,120 @@ public function path( $args ) {
}

/**
* Updates installed WP-CLI packages to their latest version.
* Gets information about an installed WP-CLI package.
*
* ## OPTIONS
*
* <name>
* : Name of the package to get information for.
*
* [--fields=<fields>]
* : Limit the output to specific fields. Defaults to all fields.
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - csv
* - json
* - yaml
* ---
*
* [--skip-update-check]
* : Skip checking for updates. This is faster and avoids authentication issues with GitHub or Composer repositories.
*
* ## AVAILABLE FIELDS
*
* These fields will be displayed by default for each package:
*
* * name
* * authors
* * version
* * update
* * update_version
*
* These fields are optionally available:
*
* * description
*
* ## EXAMPLES
*
* # Get information about an installed package.
* $ wp package get wp-cli/scaffold-package-command
* +----------------+---------------------------------+
* | Field | Value |
* +----------------+---------------------------------+
* | name | wp-cli/scaffold-package-command |
* | authors | Daniel Bachhuber |
* | version | dev-main |
* | update | available |
* | update_version | 2.x-dev |
* +----------------+---------------------------------+
*
* # Get the version of a package.
* $ wp package get wp-cli/server-command --fields=version --format=json
* {"version":"dev-main"}
*/
public function get( $args, $assoc_args ) {
list( $package_name ) = $args;
$this->set_composer_auth_env_var();

$package = $this->get_installed_package_by_name( $package_name );
if ( false === $package ) {
WP_CLI::error( sprintf( "Package '%s' is not installed.", $package_name ) );
}

$skip_update_check = Utils\get_flag_value( $assoc_args, 'skip-update-check', false );
$composer = $this->get_composer();

$package_output = [];
$package_output['name'] = $package->getPrettyName();
$package_output['description'] = $package->getDescription();
$package_output['authors'] = implode( ', ', array_column( (array) $package->getAuthors(), 'name' ) );
$package_output['version'] = $package->getPrettyVersion();
$update = 'none';
$update_version = '';

if ( ! $skip_update_check ) {
try {
$latest = $this->find_latest_package( $package, $composer, null );
if ( $latest && $latest->getFullPrettyVersion() !== $package->getFullPrettyVersion() ) {
$update = 'available';
$update_version = $latest->getPrettyVersion();
}
} catch ( Exception $e ) {
WP_CLI::warning( $e->getMessage() );
$update = 'error';
$update_version = $update;
}
}

$package_output['update'] = $update;
$package_output['update_version'] = $update_version;

$default_fields = [
'name',
'authors',
'version',
'update',
'update_version',
];

$defaults = [
'fields' => implode( ',', $default_fields ),
'format' => 'table',
];
$assoc_args = array_merge( $defaults, $assoc_args );

$formatter = new \WP_CLI\Formatter( $assoc_args );
$formatter->display_item( $package_output );
}

/**
* Updates installed WP-CLI packages to their latest version.
*
* [<package-name>...]
* : One or more package names to update. If not specified, all packages will be updated.
*
Expand Down