Skip to content

Commit

Permalink
Merge branch 'main' into fix/alias-path-requests-autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Aug 31, 2023
2 parents 3be0116 + b6ab667 commit d58dac1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
30 changes: 30 additions & 0 deletions features/aliases.feature
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,36 @@ Feature: Create shortcuts to specific WordPress installs
Error: No alias found with key '@someotherfoo'.
"""

Scenario: Adds proxyjump to ssh command
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
ssh: user@host:/path/to/wordpress
proxyjump: proxyhost
"""

When I try `wp @foo --debug --version`
Then STDERR should contain:
"""
Running SSH command: ssh -q -J 'proxyhost'
"""

Scenario: Adds key to ssh command
Given a WP installation in 'foo'
And a wp-cli.yml file:
"""
@foo:
ssh: user@host:/path/to/wordpress
key: identityfile.key
"""

When I try `wp @foo --debug --version`
Then STDERR should contain:
"""
Running SSH command: ssh -q -i 'identityfile.key'
"""

Scenario: Add an alias
Given a WP installation in 'foo'
And a wp-cli.yml file:
Expand Down
2 changes: 2 additions & 0 deletions php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Configurator {
'path',
'ssh',
'http',
'proxyjump',
'key',
];

/**
Expand Down
14 changes: 12 additions & 2 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private function generate_ssh_command( $bits, $wp_command ) {
$escaped_command = '';

// Set default values.
foreach ( [ 'scheme', 'user', 'host', 'port', 'path', 'key' ] as $bit ) {
foreach ( [ 'scheme', 'user', 'host', 'port', 'path', 'key', 'proxyjump' ] as $bit ) {
if ( ! isset( $bits[ $bit ] ) ) {
$bits[ $bit ] = null;
}
Expand Down Expand Up @@ -640,9 +640,19 @@ private function generate_ssh_command( $bits, $wp_command ) {
$bits['host'] = $bits['user'] . '@' . $bits['host'];
}

if ( ! empty( $this->alias ) ) {
$alias_config = isset( $this->aliases[ $this->alias ] ) ? $this->aliases[ $this->alias ] : false;

if ( is_array( $alias_config ) ) {
$bits['proxyjump'] = isset( $alias_config['proxyjump'] ) ? $alias_config['proxyjump'] : '';
$bits['key'] = isset( $alias_config['key'] ) ? $alias_config['key'] : '';
}
}

$command_args = [
$bits['proxyjump'] ? sprintf( '-J %s ', escapeshellarg( $bits['proxyjump'] ) ) : '',
$bits['port'] ? '-p ' . (int) $bits['port'] . ' ' : '',
$bits['key'] ? sprintf( '-i %s', $bits['key'] ) : '',
$bits['key'] ? sprintf( '-i %s', escapeshellarg( $bits['key'] ) ) : '',
$is_tty ? '-t' : '-T',
];

Expand Down

0 comments on commit d58dac1

Please sign in to comment.