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
36 changes: 28 additions & 8 deletions php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class Configurator {
*/
const ALIAS_REGEX = '^@[A-Za-z0-9-_]+$';

/**
* @var array ALIAS_SPEC Arguments that can be used in an alias
*/
private static $alias_spec = array(
'user',
'url',
'path',
'ssh',
'http',
);

/**
* @param string $path Path to config spec file.
*/
Expand Down Expand Up @@ -79,7 +90,22 @@ function get_spec() {
* @return array
*/
function get_aliases() {
return $this->aliases;
if ( $runtime_alias = getenv( 'WP_CLI_RUNTIME_ALIAS' ) ) {
$returned_aliases = array();
foreach( json_decode( $runtime_alias, true ) as $key => $value ) {
if ( preg_match( '#' . self::ALIAS_REGEX . '#', $key ) ) {
$returned_aliases[ $key ] = array();
foreach( self::$alias_spec as $i ) {
if ( isset( $value[ $i ] ) ) {
$returned_aliases[ $key ][ $i ] = $value[ $i ];
}
}
}
}
return $returned_aliases;
} else {
return $this->aliases;
}
}

/**
Expand Down Expand Up @@ -196,13 +222,7 @@ public function merge_yml( $path ) {
if ( preg_match( '#' . self::ALIAS_REGEX . '#', $key ) ) {
$this->aliases[ $key ] = array();
$is_alias = false;
foreach( array(
'user',
'url',
'path',
'ssh',
'http',
) as $i ) {
foreach( self::$alias_spec as $i ) {
if ( isset( $value[ $i ] ) ) {
$this->aliases[ $key ][ $i ] = $value[ $i ];
$is_alias = true;
Expand Down
11 changes: 11 additions & 0 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ private function run_ssh_command( $ssh ) {

if ( $this->alias && ! empty( $wp_args[0] ) && $this->alias === $wp_args[0] ) {
array_shift( $wp_args );
$runtime_alias = array();
foreach( $this->aliases[ $this->alias ] as $key => $value ) {
if ( 'ssh' === $key ) {
continue;
}
$runtime_alias[ $key ] = $value;
}
if ( ! empty( $runtime_alias ) ) {
$encoded_alias = json_encode( array( $this->alias => $runtime_alias ) );
$wp_binary = "WP_CLI_RUNTIME_ALIAS='{$encoded_alias}' {$wp_binary} {$this->alias}";
}
}

foreach( $wp_args as $k => $v ) {
Expand Down