You are here

function drush_features_export in Features 7

Same name and namespace in other branches
  1. 8.4 drush/features.drush8.inc \drush_features_export()
  2. 8.3 drush/features.drush8.inc \drush_features_export()
  3. 6 features.drush.inc \drush_features_export()
  4. 7.2 features.drush.inc \drush_features_export()

Add a component to a features module, or create a new module with the selected components.

1 call to drush_features_export()
drush_features_add in ./features.drush.inc
Add a component to a features module the selected components.

File

./features.drush.inc, line 404
Features module drush integration.

Code

function drush_features_export() {
  if ($args = func_get_args()) {
    $module = array_shift($args);
    if (empty($args)) {
      return drush_set_error('', 'No components supplied.');
    }
    $components = _drush_features_component_list();
    $options = array(
      'exported' => FALSE,
    );
    $filtered_components = _drush_features_component_filter($components, $args, $options);
    $items = $filtered_components['components'];
    if (empty($items)) {
      return drush_set_error('', 'No components to add.');
    }
    $items = array_map('array_keys', $items);
    if (($feature = features_load_feature($module, TRUE)) && module_exists($module)) {
      module_load_include('inc', 'features', 'features.export');
      _features_populate($items, $feature->info, $feature->name);
      _drush_features_export($feature->info['features'], $feature->info['dependencies'], $feature->name, dirname($feature->filename));
    }
    elseif ($feature) {
      _features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED');
    }
    else {

      // Same logic as in _drush_features_export. Should be refactored.
      $destination = drush_get_option(array(
        'destination',
      ), 'sites/all/modules');
      $directory = isset($directory) ? $directory : $destination . '/' . $module;
      drush_print(dt('Will create a new module in !dir', array(
        '!dir' => $directory,
      )));
      if (!drush_confirm(dt('Do you really want to continue?'))) {
        drush_die('Aborting.');
      }
      _drush_features_export($items, array(), $module);
    }
  }
  else {
    return drush_set_error('', 'No feature name given.');
  }
}