@@ -500,6 +500,109 @@ public function path( $args ) {
500500 WP_CLI ::line ( $ packages_dir );
501501 }
502502
503+ /**
504+ * Gets information about an installed WP-CLI package.
505+ *
506+ * ## OPTIONS
507+ *
508+ * <name>
509+ * : Name of the package to get information for.
510+ *
511+ * [--fields=<fields>]
512+ * : Limit the output to specific fields. Defaults to all fields.
513+ *
514+ * [--format=<format>]
515+ * : Render output in a particular format.
516+ * ---
517+ * default: table
518+ * options:
519+ * - table
520+ * - csv
521+ * - json
522+ * - yaml
523+ * ---
524+ *
525+ * ## AVAILABLE FIELDS
526+ *
527+ * These fields will be displayed by default for each package:
528+ *
529+ * * name
530+ * * authors
531+ * * version
532+ * * update
533+ * * update_version
534+ *
535+ * These fields are optionally available:
536+ *
537+ * * description
538+ *
539+ * ## EXAMPLES
540+ *
541+ * # Get information about an installed package.
542+ * $ wp package get wp-cli/server-command
543+ * +---------+------------------+
544+ * | Field | Value |
545+ * +---------+------------------+
546+ * | name | wp-cli/server-command |
547+ * | authors | Daniel Bachhuber |
548+ * | version | dev-main |
549+ * +---------+------------------+
550+ *
551+ * # Get the version of a package.
552+ * $ wp package get wp-cli/server-command --fields=version --format=json
553+ * {"version":"dev-main"}
554+ */
555+ public function get ( $ args , $ assoc_args ) {
556+ list ( $ package_name ) = $ args ;
557+ $ this ->set_composer_auth_env_var ();
558+
559+ $ package = $ this ->get_installed_package_by_name ( $ package_name );
560+ if ( false === $ package ) {
561+ WP_CLI ::error ( sprintf ( "Package '%s' is not installed. " , $ package_name ) );
562+ }
563+
564+ $ composer = $ this ->get_composer ();
565+
566+ $ package_output = [];
567+ $ package_output ['name ' ] = $ package ->getPrettyName ();
568+ $ package_output ['description ' ] = $ package ->getDescription ();
569+ $ package_output ['authors ' ] = implode ( ', ' , array_column ( (array ) $ package ->getAuthors (), 'name ' ) );
570+ $ package_output ['version ' ] = $ package ->getPrettyVersion ();
571+ $ update = 'none ' ;
572+ $ update_version = '' ;
573+
574+ try {
575+ $ latest = $ this ->find_latest_package ( $ package , $ composer , null );
576+ if ( $ latest && $ latest ->getFullPrettyVersion () !== $ package ->getFullPrettyVersion () ) {
577+ $ update = 'available ' ;
578+ $ update_version = $ latest ->getPrettyVersion ();
579+ }
580+ } catch ( Exception $ e ) {
581+ WP_CLI ::warning ( $ e ->getMessage () );
582+ $ update = 'error ' ;
583+ $ update_version = $ update ;
584+ }
585+
586+ $ package_output ['update ' ] = $ update ;
587+ $ package_output ['update_version ' ] = $ update_version ;
588+
589+ $ default_fields = [
590+ 'name ' ,
591+ 'authors ' ,
592+ 'version ' ,
593+ 'update ' ,
594+ 'update_version ' ,
595+ ];
596+
597+ $ defaults = [
598+ 'fields ' => implode ( ', ' , $ default_fields ),
599+ 'format ' => 'table ' ,
600+ ];
601+ $ assoc_args = array_merge ( $ defaults , $ assoc_args );
602+
603+ Utils \format_items ( $ assoc_args ['format ' ], [ $ package_output ], $ assoc_args ['fields ' ] );
604+ }
605+
503606 /**
504607 * Updates all installed WP-CLI packages to their latest version.
505608 *
0 commit comments