From 8cf6b152333c9c483d707ad339ae19e6a2b27764 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 09:59:50 +0000 Subject: [PATCH 1/9] Initial plan From 42e3337935f05e5968d92f2a3fe40005f08660ad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:20:15 +0000 Subject: [PATCH 2/9] Add wp package get command implementation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- composer.json | 1 + features/package.feature | 49 +++++++++++++++++++ src/Package_Command.php | 103 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) diff --git a/composer.json b/composer.json index 9b53625d..944f7dcf 100644 --- a/composer.json +++ b/composer.json @@ -38,6 +38,7 @@ "commands": [ "package", "package browse", + "package get", "package install", "package list", "package update", diff --git a/features/package.feature b/features/package.feature index a45218b4..734b2178 100644 --- a/features/package.feature +++ b/features/package.feature @@ -208,3 +208,52 @@ Feature: Manage WP-CLI packages """ {NO_SUCH_PACKAGE_COMPOSER_JSON} """ + + 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" + """ diff --git a/src/Package_Command.php b/src/Package_Command.php index 9e13c0d6..673c4791 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -500,6 +500,109 @@ public function path( $args ) { WP_CLI::line( $packages_dir ); } + /** + * Gets information about an installed WP-CLI package. + * + * ## OPTIONS + * + * + * : Name of the package to get information for. + * + * [--fields=] + * : Limit the output to specific fields. Defaults to all fields. + * + * [--format=] + * : Render output in a particular format. + * --- + * default: table + * options: + * - table + * - csv + * - json + * - yaml + * --- + * + * ## 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/server-command + * +---------+------------------+ + * | Field | Value | + * +---------+------------------+ + * | name | wp-cli/server-command | + * | authors | Daniel Bachhuber | + * | version | dev-main | + * +---------+------------------+ + * + * # 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 ) ); + } + + $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 = ''; + + 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 ); + + Utils\format_items( $assoc_args['format'], [ $package_output ], $assoc_args['fields'] ); + } + /** * Updates all installed WP-CLI packages to their latest version. * From 84db1bdc62e4eb70a11b9b5138ab9aca82eaf7f3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:23:22 +0000 Subject: [PATCH 3/9] Improve error handling: use N/A for update_version on error Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 673c4791..14cf50a7 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -580,7 +580,7 @@ public function get( $args, $assoc_args ) { } catch ( Exception $e ) { WP_CLI::warning( $e->getMessage() ); $update = 'error'; - $update_version = $update; + $update_version = 'N/A'; } $package_output['update'] = $update; From 9f9d8da7376e98a34b4abd17f149cb3be643a888 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 10:25:18 +0000 Subject: [PATCH 4/9] Maintain consistency with existing list command error handling Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 14cf50a7..673c4791 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -580,7 +580,7 @@ public function get( $args, $assoc_args ) { } catch ( Exception $e ) { WP_CLI::warning( $e->getMessage() ); $update = 'error'; - $update_version = 'N/A'; + $update_version = $update; } $package_output['update'] = $update; From 45d5801e8d51911683d9670b184479a11a6f3f11 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 19 Jan 2026 14:04:20 +0100 Subject: [PATCH 5/9] Update test --- features/package.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/package.feature b/features/package.feature index 2be45b97..8f56065d 100644 --- a/features/package.feature +++ b/features/package.feature @@ -274,7 +274,7 @@ Feature: Manage WP-CLI packages When I run `wp package get runcommand/hook --format=json` Then STDOUT should contain: """ - "name":"runcommand/hook" + "name":"runcommand\/hook" """ And STDOUT should contain: """ From e5cd3a5474dc73296971c80d7b5a43ae800b0005 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 19 Jan 2026 16:27:00 +0100 Subject: [PATCH 6/9] Add skip-update-check --- src/Package_Command.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index cb220c62..90f683dd 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -533,6 +533,9 @@ public function path( $args ) { * - 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: @@ -572,7 +575,8 @@ public function get( $args, $assoc_args ) { WP_CLI::error( sprintf( "Package '%s' is not installed.", $package_name ) ); } - $composer = $this->get_composer(); + $skip_update_check = Utils\get_flag_value( $assoc_args, 'skip-update-check', false ); + $composer = $this->get_composer(); $package_output = []; $package_output['name'] = $package->getPrettyName(); @@ -582,16 +586,18 @@ public function get( $args, $assoc_args ) { $update = 'none'; $update_version = ''; - try { - $latest = $this->find_latest_package( $package, $composer, null ); - if ( $latest && $latest->getFullPrettyVersion() !== $package->getFullPrettyVersion() ) { - $update = 'available'; - $update_version = $latest->getPrettyVersion(); + 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; } - } catch ( Exception $e ) { - WP_CLI::warning( $e->getMessage() ); - $update = 'error'; - $update_version = $update; } $package_output['update'] = $update; From 687bca29c195ee5338d7bc87987b6fb0ef6e5ea1 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 19 Jan 2026 16:32:45 +0100 Subject: [PATCH 7/9] Change formatting --- src/Package_Command.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 90f683dd..cb1e90e5 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -553,14 +553,16 @@ public function path( $args ) { * ## EXAMPLES * * # Get information about an installed package. - * $ wp package get wp-cli/server-command - * +---------+------------------+ - * | Field | Value | - * +---------+------------------+ - * | name | wp-cli/server-command | - * | authors | Daniel Bachhuber | - * | version | dev-main | - * +---------+------------------+ + * $ 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 @@ -617,7 +619,8 @@ public function get( $args, $assoc_args ) { ]; $assoc_args = array_merge( $defaults, $assoc_args ); - Utils\format_items( $assoc_args['format'], [ $package_output ], $assoc_args['fields'] ); + $formatter = new \WP_CLI\Formatter( $assoc_args ); + $formatter->display_item( $package_output ); } /** From 21aa896a1bdb06a9058f7cc7a37696b098fd91eb Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 19 Jan 2026 16:32:52 +0100 Subject: [PATCH 8/9] Update readme --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/README.md b/README.md index 120790a2..c0db44a3 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,70 @@ There are no optionally available fields. +### wp package get + +Gets information about an installed WP-CLI package. + +~~~ +wp package get [--fields=] [--format=] [--skip-update-check] +~~~ + +**OPTIONS** + + + Name of the package to get information for. + + [--fields=] + Limit the output to specific fields. Defaults to all fields. + + [--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. From ecc830fc3e42f849cd385e6d413fb11d7d70167d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 19 Jan 2026 16:37:56 +0100 Subject: [PATCH 9/9] Lint fix --- src/Package_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index cb1e90e5..bae5c31e 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -553,7 +553,7 @@ public function path( $args ) { * ## EXAMPLES * * # Get information about an installed package. - * $ wp package get wp-cli/scaffold-package-command * + * $ wp package get wp-cli/scaffold-package-command * +----------------+---------------------------------+ * | Field | Value | * +----------------+---------------------------------+ @@ -619,7 +619,7 @@ public function get( $args, $assoc_args ) { ]; $assoc_args = array_merge( $defaults, $assoc_args ); - $formatter = new \WP_CLI\Formatter( $assoc_args ); + $formatter = new \WP_CLI\Formatter( $assoc_args ); $formatter->display_item( $package_output ); }