@@ -503,8 +503,14 @@ public function path( $args ) {
503503 /**
504504 * Updates all installed WP-CLI packages to their latest version.
505505 *
506+ * ## OPTIONS
507+ *
508+ * [<package-name>...]
509+ * : One or more package names to update. If not specified, all packages will be updated.
510+ *
506511 * ## EXAMPLES
507512 *
513+ * # Update all packages.
508514 * $ wp package update
509515 * Using Composer to update packages...
510516 * ---
@@ -518,9 +524,34 @@ public function path( $args ) {
518524 * Generating autoload files
519525 * ---
520526 * Success: Packages updated.
527+ *
528+ * # Update a specific package.
529+ * $ wp package update wp-cli/server-command
530+ * Using Composer to update packages...
531+ * ---
532+ * Loading composer repositories with package information
533+ * Updating dependencies
534+ * Writing lock file
535+ * Generating autoload files
536+ * ---
537+ * Success: Package updated successfully.
521538 */
522- public function update () {
539+ public function update ( $ args = [] ) {
523540 $ this ->set_composer_auth_env_var ();
541+
542+ // Validate package names if provided
543+ $ packages_to_update = [];
544+ if ( ! empty ( $ args ) ) {
545+ foreach ( $ args as $ package_name ) {
546+ $ package = $ this ->get_installed_package_by_name ( $ package_name );
547+ if ( false === $ package ) {
548+ WP_CLI ::error ( sprintf ( "Package '%s' is not installed. " , $ package_name ) );
549+ }
550+ // Use the package's pretty name (case-sensitive) from composer
551+ $ packages_to_update [] = $ package ->getPrettyName ();
552+ }
553+ }
554+
524555 $ composer = $ this ->get_composer ();
525556
526557 // Set up the EventSubscriber
@@ -531,6 +562,12 @@ public function update() {
531562 $ install = Installer ::create ( new ComposerIO (), $ composer );
532563 $ install ->setUpdate ( true ); // Installer class will only override composer.lock with this flag
533564 $ install ->setPreferSource ( true ); // Use VCS when VCS for easier contributions.
565+
566+ // If specific packages are provided, use the allow list
567+ if ( ! empty ( $ packages_to_update ) ) {
568+ $ install ->setUpdateAllowList ( $ packages_to_update );
569+ }
570+
534571 WP_CLI ::log ( 'Using Composer to update packages... ' );
535572 WP_CLI ::log ( '--- ' );
536573 $ res = false ;
@@ -544,7 +581,15 @@ public function update() {
544581 // TODO: The --insecure (to be added here) flag should cause another Composer run with verify disabled.
545582
546583 if ( 0 === $ res ) {
547- WP_CLI ::success ( 'Packages updated. ' );
584+ if ( ! empty ( $ packages_to_update ) ) {
585+ if ( 1 === count ( $ packages_to_update ) ) {
586+ WP_CLI ::success ( 'Package updated successfully. ' );
587+ } else {
588+ WP_CLI ::success ( sprintf ( '%d packages updated successfully. ' , count ( $ packages_to_update ) ) );
589+ }
590+ } else {
591+ WP_CLI ::success ( 'Packages updated. ' );
592+ }
548593 } else {
549594 $ res_msg = $ res ? " (Composer return code {$ res }) " : '' ; // $res may be null apparently.
550595 WP_CLI ::error ( "Failed to update packages {$ res_msg }. " );
0 commit comments