Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,57 @@ Feature: Have a config file
{"bar":"burrito","apple":"apple"}
"""

Scenario: Config inheritance in nested folders
Given an empty directory
And a wp-cli.local.yml file:
"""
@dev:
ssh: vagrant@example.test/srv/www/example.com/current
path: web/wp
"""
And a site/wp-cli.yml file:
"""
_:
inherit: ../wp-cli.local.yml
@otherdev:
ssh: vagrant@otherexample.test/srv/www/otherexample.com/current
"""
And a site/public/index.php file:
"""
<?php
"""

When I run `wp cli alias list`
Then STDOUT should contain:
"""
@all: Run command against every registered alias.
@dev:
path: web/wp
ssh: vagrant@example.test/srv/www/example.com/current
"""

When I run `cd site && wp cli alias list`
Then STDOUT should contain:
"""
@all: Run command against every registered alias.
@dev:
path: web/wp
ssh: vagrant@example.test/srv/www/example.com/current
@otherdev:
ssh: vagrant@otherexample.test/srv/www/otherexample.com/current
"""

When I run `cd site/public && wp cli alias list`
Then STDOUT should contain:
"""
@all: Run command against every registered alias.
@dev:
path: web/wp
ssh: vagrant@example.test/srv/www/example.com/current
@otherdev:
ssh: vagrant@otherexample.test/srv/www/otherexample.com/current
"""

@require-wp-3.9
Scenario: WordPress installation with local dev DOMAIN_CURRENT_SITE
Given a WP multisite installation
Expand Down
12 changes: 11 additions & 1 deletion php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace WP_CLI;

use Mustangostang\Spyc;
use SplFileInfo;

use function WP_CLI\Utils\is_path_absolute;
use function WP_CLI\Utils\normalize_path;

/**
* Handles file- and runtime-based configuration values.
Expand Down Expand Up @@ -253,7 +257,13 @@ private function assoc_arg_to_runtime_config( $key, $value, &$runtime_config ) {
public function merge_yml( $path, $current_alias = null ) {
$yaml = self::load_yml( $path );
if ( ! empty( $yaml['_']['inherit'] ) ) {
$this->merge_yml( $yaml['_']['inherit'], $current_alias );
// Refactor with the WP-CLI `Path` class, once it's available.
// See: https://github.com/wp-cli/wp-cli/issues/5007
$inherit_path = is_path_absolute( $yaml['_']['inherit'] )
? $yaml['_']['inherit']
: ( new SplFileInfo( normalize_path( dirname( $path ) . '/' . $yaml['_']['inherit'] ) ) )->getRealPath();

$this->merge_yml( $inherit_path, $current_alias );
}
// Prepare the base path for absolutized alias paths.
$yml_file_dir = $path ? dirname( $path ) : false;
Expand Down