@@ -78,6 +78,13 @@ class Find_Command {
7878 */
7979 private $ start_time = false ;
8080
81+ /**
82+ * Resolved alias paths
83+ *
84+ * @var array
85+ */
86+ private $ resolved_aliases = array ();
87+
8188 /**
8289 * Found WordPress installs.
8390 *
@@ -95,13 +102,16 @@ class Find_Command {
95102 * Avoids recursing some known paths (e.g. node_modules) to significantly
96103 * improve performance.
97104 *
105+ * Indicates depth at which the WordPress install was found, and its alias,
106+ * if it has one.
107+ *
98108 * ```
99109 * $ wp find ./
100- * +--------------------------------------------------------------------- +------------- --------+
101- * | version_path | version |
102- * +--------------------------------------------------------------------- +------------- --------+
103- * | /Users/wpcli/projects/wordpress-develop/src/ wp-includes/version.php | 4.8-alpha-39357-src |
104- * +--------------------------------------------------------------------- +------------- --------+
110+ * +--------------------------------------+ ---------------------+-------+ --------+
111+ * | version_path | version | depth | alias |
112+ * +--------------------------------------+ ---------------------+-------+ --------+
113+ * | /Users/wpcli/wp-includes/version.php | 4.8-alpha-39357-src | 2 | @wpcli |
114+ * +--------------------------------------+ ---------------------+-------+ --------+
105115 * ```
106116 *
107117 * ## OPTIONS
@@ -147,10 +157,19 @@ public function __invoke( $args, $assoc_args ) {
147157 $ this ->skip_ignored_paths = Utils \get_flag_value ( $ assoc_args , 'skip-ignored-paths ' );
148158 $ this ->max_depth = Utils \get_flag_value ( $ assoc_args , 'max_depth ' , false );
149159 $ this ->verbose = Utils \get_flag_value ( $ assoc_args , 'verbose ' );
160+
161+ $ aliases = WP_CLI ::get_runner ()->aliases ;
162+ foreach ( $ aliases as $ alias => $ target ) {
163+ if ( empty ( $ target ['path ' ] ) ) {
164+ continue ;
165+ }
166+ $ this ->resolved_aliases [ rtrim ( $ target ['path ' ], '/ ' ) ] = $ alias ;
167+ }
168+
150169 $ this ->start_time = microtime ( true );
151170 $ this ->log ( "Searching for WordPress installs in ' {$ path }' " );
152171 $ this ->recurse_directory ( $ this ->base_path );
153- $ formatter = new \WP_CLI \Formatter ( $ assoc_args , array ( 'version_path ' , 'version ' , 'depth ' ) );
172+ $ formatter = new \WP_CLI \Formatter ( $ assoc_args , array ( 'version_path ' , 'version ' , 'depth ' , ' alias ' ) );
154173 $ formatter ->display_items ( $ this ->found_wp );
155174 }
156175
@@ -181,10 +200,13 @@ private function recurse_directory( $path ) {
181200 if ( '/wp-includes/ ' === substr ( $ path , -13 )
182201 && file_exists ( $ path . 'version.php ' ) ) {
183202 $ version_path = $ path . 'version.php ' ;
203+ $ wp_path = substr ( $ path , 0 , -13 );
204+ $ alias = isset ( $ this ->resolved_aliases [ $ wp_path ] ) ? $ this ->resolved_aliases [ $ wp_path ] : '' ;
184205 $ this ->found_wp [ $ version_path ] = array (
185206 'version_path ' => $ version_path ,
186207 'version ' => self ::get_wp_version ( $ version_path ),
187208 'depth ' => $ this ->current_depth - 1 ,
209+ 'alias ' => $ alias ,
188210 );
189211 $ this ->log ( "Found WordPress install at ' {$ version_path }' " );
190212 return ;
0 commit comments