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
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