Skip to content

Commit bba57a7

Browse files
authored
Merge pull request #5930 from tfirdaus/fix/4958-config-inheritance
2 parents 7f1409e + 74c8c65 commit bba57a7

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

features/config.feature

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,57 @@ Feature: Have a config file
476476
{"bar":"burrito","apple":"apple"}
477477
"""
478478

479+
Scenario: Config inheritance in nested folders
480+
Given an empty directory
481+
And a wp-cli.local.yml file:
482+
"""
483+
@dev:
484+
ssh: vagrant@example.test/srv/www/example.com/current
485+
path: web/wp
486+
"""
487+
And a site/wp-cli.yml file:
488+
"""
489+
_:
490+
inherit: ../wp-cli.local.yml
491+
@otherdev:
492+
ssh: vagrant@otherexample.test/srv/www/otherexample.com/current
493+
"""
494+
And a site/public/index.php file:
495+
"""
496+
<?php
497+
"""
498+
499+
When I run `wp cli alias list`
500+
Then STDOUT should contain:
501+
"""
502+
@all: Run command against every registered alias.
503+
@dev:
504+
path: web/wp
505+
ssh: vagrant@example.test/srv/www/example.com/current
506+
"""
507+
508+
When I run `cd site && wp cli alias list`
509+
Then STDOUT should contain:
510+
"""
511+
@all: Run command against every registered alias.
512+
@dev:
513+
path: web/wp
514+
ssh: vagrant@example.test/srv/www/example.com/current
515+
@otherdev:
516+
ssh: vagrant@otherexample.test/srv/www/otherexample.com/current
517+
"""
518+
519+
When I run `cd site/public && wp cli alias list`
520+
Then STDOUT should contain:
521+
"""
522+
@all: Run command against every registered alias.
523+
@dev:
524+
path: web/wp
525+
ssh: vagrant@example.test/srv/www/example.com/current
526+
@otherdev:
527+
ssh: vagrant@otherexample.test/srv/www/otherexample.com/current
528+
"""
529+
479530
@require-wp-3.9
480531
Scenario: WordPress installation with local dev DOMAIN_CURRENT_SITE
481532
Given a WP multisite installation

php/WP_CLI/Configurator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace WP_CLI;
44

55
use Mustangostang\Spyc;
6+
use SplFileInfo;
7+
8+
use function WP_CLI\Utils\is_path_absolute;
9+
use function WP_CLI\Utils\normalize_path;
610

711
/**
812
* Handles file- and runtime-based configuration values.
@@ -253,7 +257,13 @@ private function assoc_arg_to_runtime_config( $key, $value, &$runtime_config ) {
253257
public function merge_yml( $path, $current_alias = null ) {
254258
$yaml = self::load_yml( $path );
255259
if ( ! empty( $yaml['_']['inherit'] ) ) {
256-
$this->merge_yml( $yaml['_']['inherit'], $current_alias );
260+
// Refactor with the WP-CLI `Path` class, once it's available.
261+
// See: https://github.com/wp-cli/wp-cli/issues/5007
262+
$inherit_path = is_path_absolute( $yaml['_']['inherit'] )
263+
? $yaml['_']['inherit']
264+
: ( new SplFileInfo( normalize_path( dirname( $path ) . '/' . $yaml['_']['inherit'] ) ) )->getRealPath();
265+
266+
$this->merge_yml( $inherit_path, $current_alias );
257267
}
258268
// Prepare the base path for absolutized alias paths.
259269
$yml_file_dir = $path ? dirname( $path ) : false;

0 commit comments

Comments
 (0)