function _drush_merge_engine_data

5.x command.inc _drush_merge_engine_data(&$command)

Add command structure info from each engine back into the command.

Related topics

2 calls to _drush_merge_engine_data()
drush_get_commands in includes/command.inc
Get a list of all implemented commands. This invokes hook_drush_command().
_drush_usage_log in commands/core/usage.drush.inc

File

includes/command.inc, line 453
The drush command engine.

Code

function _drush_merge_engine_data(&$command) {
  foreach ($command['engines'] as $engine_type => $config) {
    // Normalize engines structure.
    if (!is_array($config)) {
      unset($command['engines'][$engine_type]);
      $command['engines'][$config] = array();
      $engine_type = $config;
    }

    // Get all implementations for this engine type.
    $engine_info = drush_get_engines($engine_type);
    if ($engine_info === FALSE) {
      return FALSE;
    }

    // Override engine_info with customizations in the command.
    $config = $command['engines'][$engine_type] += $engine_info['info'];

    // Add engine type global options to the command.
    $command['options'] += $config['options'];

    $engine_data = array();

    // If there's a single implementation for this engine type, it will be
    // loaded by default, and makes no sense to provide a command line option
    // to select the only flavor (ie. --release_info=updatexml), so we won't
    // add an option in this case.
    // Additionally, depending on the command, it may be convenient to extend
    // the command with the engine options.
    if (count($engine_info['engines']) == 1) {
      if ($config['add-options-to-command'] !== FALSE) {
        $engine = key($engine_info['engines']);
        $data = $engine_info['engines'][$engine];
        foreach (array('options', 'sub-options') as $key) {
          if (isset($data[$key])) {
            $engine_data[$key] = $data[$key];
          }
        }
      }
    }
    // Otherwise, provide a command option to choose between engines and add
    // the engine options and sub-obtions.
    else {
      // Process engines in order. First the default engine, the rest alphabetically.
      $default = $config['default'];
      $engines = array_keys($engine_info['engines']);
      asort($engines);
      array_unshift($engines, $default);
      $engines = array_unique($engines);

      // Extend the default engine description.
      $desc = $engine_info['engines'][$default]['description'];
      $engine_info['engines'][$default]['description'] = dt('Default type engine.', array('type' => $engine_type)) . ' ' . $desc;

      $engine_data += array(
        'options' => array(),
        'sub-options' => array(),
      );
      foreach ($engines as $engine) {
        $data = $engine_info['engines'][$engine];
        $option = $config['option'] . '=' . $engine;
        $engine_data['options'][$option] = array_key_exists('description', $data) ? $data['description'] : NULL;
        if (isset($data['options'])) {
          $engine_data['sub-options'][$option] = $data['options'];
        }
        if (isset($data['sub-options'])) {
          $engine_data['sub-options'] += $data['sub-options'];
        }
      }
    }
    $command = array_merge_recursive($command, $engine_data);
  }
}