Skip to content
Closed
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
2 changes: 1 addition & 1 deletion includes/backend.inc
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ function drush_backend_invoke_concurrent($invocations, $common_options = array()
}
$site_record += array('path-aliases' => array(), '#env-vars' => array());
$site_record['path-aliases'] += array(
'%drush-script' => NULL,
'%drush-script' => $backend_options['drush-script'],
);

$site = (array_key_exists('#name', $site_record) && !array_key_exists($site_record['#name'], $invocation_options)) ? $site_record['#name'] : $index++;
Expand Down
48 changes: 37 additions & 11 deletions includes/drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function drush_get_global_options($brief = FALSE) {
$options['quiet'] = array('short-form' => 'q', 'description' => 'Suppress non-error messages.');
$options['include'] = array('short-form' => 'i', 'short-has-arg' => TRUE, 'context' => 'DRUSH_INCLUDE', 'never-post' => TRUE, 'propagate-cli-value' => TRUE, 'merge-pathlist' => TRUE, 'description' => "A list of additional directory paths to search for drush commands.", 'example-value' => '/path/dir');
$options['exclude'] = array('propagate-cli-value' => TRUE, 'never-post' => TRUE, 'merge-pathlist' => TRUE, 'description' => "A list of files and directory paths to exclude from consideration when searching for drush commandfiles.", 'example-value' => '/path/dir');
$options['config'] = array('short-form' => 'c', 'short-has-arg' => TRUE, 'context' => 'DRUSH_CONFIG', 'local-context-only' => TRUE, 'merge-pathlist' => TRUE, 'description' => "Specify an additional config file to load. See example.drushrc.php.", 'example-value' => '/path/file');
$options['config'] = array('short-form' => 'c', 'short-has-arg' => TRUE, 'context' => 'DRUSH_CONFIG', 'never-post' => TRUE, 'propagate-cli-value' => TRUE, 'merge-pathlist' => TRUE, 'description' => "Specify an additional config file to load. See example.drushrc.php.", 'example-value' => '/path/file');
$options['user'] = array('short-form' => 'u', 'short-has-arg' => TRUE, 'propagate-cli-value' => TRUE, 'description' => "Specify a Drupal user to login with. May be a name or a number.", 'example-value' => 'name_or_number');
$options['backend'] = array('short-form' => 'b', 'never-propagate' => TRUE, 'description' => "Hide all output and return structured data.");
$options['choice'] = array('description' => "Provide an answer to a multiple-choice prompt.", 'example-value' => 'number');
Expand Down Expand Up @@ -1098,6 +1098,7 @@ function drush_preflight_command_dispatch() {
// option will be set when the site alias is processed.
// @see drush_sitealias_check_arg
$remote_host = drush_get_option('remote-host');
$site_list = drush_get_option('site-list');
// Get the command early so that we can allow commands to directly handle remote aliases if they wish
$command = drush_parse_command();
drush_command_default_options($command);
Expand Down Expand Up @@ -1134,31 +1135,48 @@ function drush_preflight_command_dispatch() {
drush_set_context('cli', $cli_options);
_drush_preflight_global_options();
}
$args = drush_get_arguments();
$command_name = array_shift($args);
$root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT');
$local_drush = drush_get_option('drush-script');
$is_local = drush_get_option('local');
$values = NULL;
if (!empty($root) && !empty($local_drush) && empty($is_local)) {
if (!drush_is_absolute_path($local_drush)) {
$local_drush = $root . '/' . $local_drush;
}
$local_drush = realpath($local_drush);
$this_drush = realpath($GLOBALS['argv'][0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to grab from GLOBALS here? Maybe drush_build_drush_command() is helpful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks; I was lazy and then forgot to go back and fix it. I'll improve it in the next commit.

// If there is a local drush selected, and it is not the
// same drush that is currently running, redispatch to it.
if (file_exists($local_drush) && ($this_drush != $local_drush)) {
$uri = drush_get_context('DRUSH_SELECTED_URI');
$aditional_options = array(
'root' => $root,
'local' => TRUE,
);
if (!empty($uri)) {
$aditional_options['uri'] = $uri;
}
$values = drush_do_command_redispatch(is_array($command) ? $command : $command_name, $args, NULL, NULL, $local_drush, TRUE, $aditional_options);
}
}
// If the command sets the 'handle-remote-commands' flag, then we will short-circuit
// remote command dispatching and site-list command dispatching, and always let
// the command handler run on the local machine.
if (is_array($command) && !empty($command['handle-remote-commands'])) {
return FALSE;
}
if (isset($remote_host)) {
$args = drush_get_arguments();
$command_name = array_shift($args);
$remote_user = drush_get_option('remote-user');

// Force interactive mode if there is a single remote target. #interactive is added by drush_do_command_redispatch
$user_interactive = drush_get_option('interactive');
drush_set_option('interactive', TRUE);
$values = drush_do_command_redispatch(is_array($command) ? $command : $command_name, $args, $remote_host, $remote_user, $user_interactive);
if ($values['error_status'] > 0) {
// Force an error result code. Note that drush_shutdown() will still run.
drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);
exit($values);
}
return TRUE;
}
// If the --site-list flag is set, then we will execute the specified
// command once for every site listed in the site list.
$site_list = drush_get_option('site-list');
if (isset($site_list)) {
if (!is_array($site_list)) {
$site_list = explode(',', $site_list);
Expand Down Expand Up @@ -1205,6 +1223,13 @@ function drush_preflight_command_dispatch() {
}
}
$values = drush_invoke_process($site_record, $command_name, $args, $multi_options, $backend_options);
}
if (isset($values)) {
if (is_array($values) && ($values['error_status'] > 0)) {
// Force an error result code. Note that drush_shutdown() will still run.
drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);
exit($values);
}
return TRUE;
}
return FALSE;
Expand Down Expand Up @@ -1261,9 +1286,10 @@ function _drush_should_remove_command_arg($arg, $removal_list) {
* Redispatch the specified command using the same
* options that were passed to this invocation of drush.
*/
function drush_do_command_redispatch($command, $args = array(), $remote_host = NULL, $remote_user = NULL, $drush_path = NULL, $user_interactive = FALSE) {
function drush_do_command_redispatch($command, $args = array(), $remote_host = NULL, $remote_user = NULL, $drush_path = NULL, $user_interactive = FALSE, $aditional_options = array()) {
$additional_global_options = array();
$command_options = drush_redispatch_get_options();
$command_options = $aditional_options + $command_options;
if (is_array($command)) {
$command_name = $command['command'];
// If we are executing a remote command that uses strict option handling,
Expand Down
5 changes: 3 additions & 2 deletions tests/shellAliasTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ public function testShellAliasDrushRemote() {
$this->drush('glopts', array(), $options, 'user@server/path/to/drupal#sitename');
// $expected might be different on non unix platforms. We shall see.
// n.b. --config is not included in calls to remote systems.
$bash = $this->escapeshellarg('drush --nocolor --uri=sitename --root=/path/to/drupal core-topic core-global-options 2>&1');
$bash = $this->escapeshellarg('drush --config=drush-sandbox --nocolor --uri=sitename --root=/path/to/drupal core-topic core-global-options 2>&1');
$expected = "Simulating backend invoke: ssh -t user@server $bash 2>&1";
$output = $this->getOutput();
// Remove any coverage arguments. The filename changes, so it's not possible
// to create a string for assertEquals, and the need for both shell escaping
// and regexp escaping different parts of the expected output for
// assertRegexp makes it easier just to remove the argument before checking
// the output.
$output = preg_replace('{--drush-coverage=[a-zA-Z0-9/_]+ }', '', $output);
$output = preg_replace('{--drush-coverage=[^ ]+ }', '', $output);
$output = preg_replace('{--config=[^ ]+ +}', '--config=drush-sandbox ', $output);
$this->assertEquals($expected, $output, 'Expected remote shell alias to a drush command was built');
}

Expand Down