@@ -507,10 +507,120 @@ public function path( $args ) {
507507 }
508508
509509 /**
510- * Updates installed WP-CLI packages to their latest version .
510+ * Gets information about an installed WP-CLI package .
511511 *
512512 * ## OPTIONS
513513 *
514+ * <name>
515+ * : Name of the package to get information for.
516+ *
517+ * [--fields=<fields>]
518+ * : Limit the output to specific fields. Defaults to all fields.
519+ *
520+ * [--format=<format>]
521+ * : Render output in a particular format.
522+ * ---
523+ * default: table
524+ * options:
525+ * - table
526+ * - csv
527+ * - json
528+ * - yaml
529+ * ---
530+ *
531+ * [--skip-update-check]
532+ * : Skip checking for updates. This is faster and avoids authentication issues with GitHub or Composer repositories.
533+ *
534+ * ## AVAILABLE FIELDS
535+ *
536+ * These fields will be displayed by default for each package:
537+ *
538+ * * name
539+ * * authors
540+ * * version
541+ * * update
542+ * * update_version
543+ *
544+ * These fields are optionally available:
545+ *
546+ * * description
547+ *
548+ * ## EXAMPLES
549+ *
550+ * # Get information about an installed package.
551+ * $ wp package get wp-cli/scaffold-package-command
552+ * +----------------+---------------------------------+
553+ * | Field | Value |
554+ * +----------------+---------------------------------+
555+ * | name | wp-cli/scaffold-package-command |
556+ * | authors | Daniel Bachhuber |
557+ * | version | dev-main |
558+ * | update | available |
559+ * | update_version | 2.x-dev |
560+ * +----------------+---------------------------------+
561+ *
562+ * # Get the version of a package.
563+ * $ wp package get wp-cli/server-command --fields=version --format=json
564+ * {"version":"dev-main"}
565+ */
566+ public function get ( $ args , $ assoc_args ) {
567+ list ( $ package_name ) = $ args ;
568+ $ this ->set_composer_auth_env_var ();
569+
570+ $ package = $ this ->get_installed_package_by_name ( $ package_name );
571+ if ( false === $ package ) {
572+ WP_CLI ::error ( sprintf ( "Package '%s' is not installed. " , $ package_name ) );
573+ }
574+
575+ $ skip_update_check = Utils \get_flag_value ( $ assoc_args , 'skip-update-check ' , false );
576+ $ composer = $ this ->get_composer ();
577+
578+ $ package_output = [];
579+ $ package_output ['name ' ] = $ package ->getPrettyName ();
580+ $ package_output ['description ' ] = $ package ->getDescription ();
581+ $ package_output ['authors ' ] = implode ( ', ' , array_column ( (array ) $ package ->getAuthors (), 'name ' ) );
582+ $ package_output ['version ' ] = $ package ->getPrettyVersion ();
583+ $ update = 'none ' ;
584+ $ update_version = '' ;
585+
586+ if ( ! $ skip_update_check ) {
587+ try {
588+ $ latest = $ this ->find_latest_package ( $ package , $ composer );
589+ if ( $ latest && $ latest ->getFullPrettyVersion () !== $ package ->getFullPrettyVersion () ) {
590+ $ update = 'available ' ;
591+ $ update_version = $ latest ->getPrettyVersion ();
592+ }
593+ } catch ( Exception $ e ) {
594+ WP_CLI ::warning ( $ e ->getMessage () );
595+ $ update = 'error ' ;
596+ $ update_version = $ update ;
597+ }
598+ }
599+
600+ $ package_output ['update ' ] = $ update ;
601+ $ package_output ['update_version ' ] = $ update_version ;
602+
603+ $ default_fields = [
604+ 'name ' ,
605+ 'authors ' ,
606+ 'version ' ,
607+ 'update ' ,
608+ 'update_version ' ,
609+ ];
610+
611+ $ defaults = [
612+ 'fields ' => implode ( ', ' , $ default_fields ),
613+ 'format ' => 'table ' ,
614+ ];
615+ $ assoc_args = array_merge ( $ defaults , $ assoc_args );
616+
617+ $ formatter = new \WP_CLI \Formatter ( $ assoc_args );
618+ $ formatter ->display_item ( $ package_output );
619+ }
620+
621+ /**
622+ * Updates installed WP-CLI packages to their latest version.
623+ *
514624 * [<package-name>...]
515625 * : One or more package names to update. If not specified, all packages will be updated.
516626 *
0 commit comments