Skip to content

Commit

Permalink
Merge pull request #2533 from wp-cli/1564-cli-info-packages
Browse files Browse the repository at this point in the history
Add package directory path to `wp cli info`
  • Loading branch information
danielbachhuber committed Mar 7, 2016
2 parents 262d67e + 6b700a7 commit e00826a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
16 changes: 16 additions & 0 deletions features/cli-info.feature
@@ -0,0 +1,16 @@
Feature: Review CLI information

Scenario: Get the path to the packages directory
Given an empty directory

When I run `wp cli info --format=json`
Then STDOUT should be JSON containing:
"""
{"wp_cli_packages_dir_path":"/tmp/wp-cli-home/.wp-cli/packages/"}
"""

When I run `WP_CLI_PACKAGES_DIR=/tmp/packages wp cli info --format=json`
Then STDOUT should be JSON containing:
"""
{"wp_cli_packages_dir_path":"/tmp/packages/"}
"""
20 changes: 15 additions & 5 deletions php/WP_CLI/Runner.php
Expand Up @@ -118,6 +118,20 @@ private function get_project_config_path() {
return $project_config_path;
}

/**
* Get the path to the packages directory
*
* @return string
*/
public function get_packages_dir_path() {
if ( getenv( 'WP_CLI_PACKAGES_DIR' ) ) {
$packages_dir = rtrim( getenv( 'WP_CLI_PACKAGES_DIR' ), '/' ) . '/';
} else {
$packages_dir = getenv( 'HOME' ) . '/.wp-cli/packages/';
}
return $packages_dir;
}

/**
* Attempts to find the path to the WP install inside index.php
*
Expand Down Expand Up @@ -609,11 +623,7 @@ public function start() {
// APIs as non-bundled commands.
Utils\load_command( $this->arguments[0] );

if ( getenv( 'WP_CLI_PACKAGES_DIR' ) ) {
$package_autoload = rtrim( getenv( 'WP_CLI_PACKAGES_DIR' ), '/' ) . '/vendor/autoload.php';
} else {
$package_autoload = getenv( 'HOME' ) . '/.wp-cli/packages/vendor/autoload.php';
}
$package_autoload = $this->get_packages_dir_path() . 'vendor/autoload.php';

if ( file_exists( $package_autoload ) ) {
WP_CLI::debug( 'Loading packages from: ' . $package_autoload );
Expand Down
2 changes: 2 additions & 0 deletions php/commands/cli.php
Expand Up @@ -55,6 +55,7 @@ public function info( $_, $assoc_args ) {
'global_config_path' => $runner->global_config_path,
'project_config_path' => $runner->project_config_path,
'wp_cli_dir_path' => WP_CLI_ROOT,
'wp_cli_packages_dir_path' => $runner->get_packages_dir_path(),
'wp_cli_version' => WP_CLI_VERSION,
);

Expand All @@ -64,6 +65,7 @@ public function info( $_, $assoc_args ) {
WP_CLI::line( "PHP version:\t" . PHP_VERSION );
WP_CLI::line( "php.ini used:\t" . get_cfg_var( 'cfg_file_path' ) );
WP_CLI::line( "WP-CLI root dir:\t" . WP_CLI_ROOT );
WP_CLI::line( "WP-CLI packages dir:\t" . $runner->get_packages_dir_path() );
WP_CLI::line( "WP-CLI global config:\t" . $runner->global_config_path );
WP_CLI::line( "WP-CLI project config:\t" . $runner->project_config_path );
WP_CLI::line( "WP-CLI version:\t" . WP_CLI_VERSION );
Expand Down

0 comments on commit e00826a

Please sign in to comment.