function drush_features_add in Features 6
Same name and namespace in other branches
- 8.4 drush/features.drush8.inc \drush_features_add()
- 8.3 drush/features.drush8.inc \drush_features_add()
- 7.2 features.drush.inc \drush_features_add()
- 7 features.drush.inc \drush_features_add()
Add a component to a features module.
File
- ./
features.drush.inc, line 186 - Features module drush integration.
Code
function drush_features_add() {
if ($args = func_get_args()) {
// Get a complete list of components.
$all_components = array();
foreach (features_get_components(TRUE) as $source => $info) {
if ($options = features_invoke($source, 'features_export_options')) {
foreach ($options as $key => $value) {
$all_components[$key][] = $source;
}
}
}
$module = array_shift($args);
while ($arg = trim(array_shift($args))) {
list($source, $component) = explode(':', $arg);
if ($component) {
if (isset($all_components[$component]) && in_array($source, $all_components[$component])) {
$items[$source][] = $component;
}
else {
$choice = _drush_features_component_find($component, $source);
if ($choice !== FALSE) {
drush_print(dt('Selected component "!component".', array(
'!component' => $choice->source . ':' . $choice->component,
)));
$items[$choice->source][] = $choice->component;
continue;
}
return drush_set_error('', dt('Unknown component !arg', array(
'!arg' => $arg,
)));
}
}
else {
if ($all_components[$source] && sizeof($all_components[$source]) == 1) {
$items[$all_components[$source][0]][] = $source;
}
elseif (isset($all_components[$source])) {
return drush_set_error('', dt('Ambiguous component !component, possible sources: !sources', array(
'!component' => $source,
'!sources' => join(', ', $all_components[$source]),
)));
}
else {
$choice = _drush_features_component_find($component, $source);
if ($choice !== FALSE) {
drush_print(dt('Selected component "!component".', array(
'!component' => $choice->source . ':' . $choice->component,
)));
$items[$choice->source][] = $choice->component;
continue;
}
return drush_set_error('', dt('Unknown component !arg', array(
'!arg' => $arg,
)));
}
}
}
if (!$items) {
// Print out a list of available items.
_drush_features_component_list();
return;
}
if (($feature = feature_load($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 {
_features_drush_set_error($module);
}
}
else {
// By default just show features that are available.
$rows = array(
array(
dt('Available features'),
),
);
foreach (features_get_features(NULL, TRUE) as $name => $info) {
$rows[] = array(
$name,
);
}
drush_print_table($rows, TRUE);
}
}