function drush_remote_command

3.x drush.inc drush_remote_command()
4.x drush.inc drush_remote_command()

Process commands that are executed on a remote drush instance.

Return value

TRUE if the command was handled remotely.

Related topics

1 call to drush_remote_command()
drush_main in ./drush.php
The main Drush function.

File

includes/drush.inc, line 2193
The drush API implementation and helpers.

Code

function drush_remote_command() {
  // The command will be executed remotely if the --remote-host flag
  // is set; note that if a site alias is provided on the command line,
  // and the site alias references a remote server, then the --remote-host
  // option will be set when the site alias is processed.
  // @see _drush_process_site_alias
  $remote_host = drush_get_option('remote-host');
  if (isset($remote_host)) {

    $args = drush_get_arguments();
    $command = array_shift($args);
    $remote_user = drush_get_option('remote-user');

    drush_do_command_redispatch($command, $args, $remote_host, $remote_user);
    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);
    }
    $site_list = drush_sitealias_resolve_sitespecs($site_list);
    $site_list = drush_sitealias_simplify_names($site_list);
    $args = drush_get_arguments();

    if (!drush_get_context('DRUSH_SIMULATE')) {
      drush_print(dt("You are about to execute '!command' on all of the following targets:", array('!command' => implode(" ", $args))));
      foreach ($site_list as $one_destination => $one_record) {
        drush_print(dt('  !target', array('!target' => $one_destination)));
      }

      if (drush_confirm('Continue? ') === FALSE) {
        drush_user_abort();
        return TRUE;
      }
    }
    $command = array_shift($args);
    $multi_options = drush_get_context('cli');

    if (!drush_get_option('no-label', FALSE)) {
      $label_separator = ' >> ';
      $max_name_length = 0;
      foreach ($site_list as $alias_name => $alias_record) {
        if (strlen($alias_name) > $max_name_length) {
          $max_name_length = strlen($alias_name);
        }
      }
      $multi_options['reserve-margin'] = $max_name_length + strlen($label_separator);
      foreach ($site_list as $alias_name => $alias_record) {
        $values = drush_do_site_command($alias_record, $command, $args, $multi_options);
        foreach (explode("\n", $values['output']) as $line) {
          if (empty($line)) {
            drush_print();
          }
          else {
            drush_print(str_pad($alias_name, $max_name_length, " ") . $label_separator . $line);
          }
        }
      }
    }
    else {
      foreach ($site_list as $alias_name => $alias_record) {
        $values = drush_do_site_command($alias_record, $command, $args, $multi_options);
        drush_print($values['output']);
      }
    }
    return TRUE;
  }
  return FALSE;
}