function drush_environment_switch in Environment 7
Same name and namespace in other branches
- 8 environment.drush.inc \drush_environment_switch()
- 6 environment.drush.inc \drush_environment_switch()
Implements drush_hook_COMMAND for environment_switch.
File
- ./
environment.drush.inc, line 83 - Executes the environment_switch capabilities.
Code
function drush_environment_switch($target_env = NULL) {
if ($target_env && !array_key_exists($target_env, environment_load())) {
drush_set_error('DRUSH_ENVIRONMENT_ERROR', dt('Invalid environment specified.'));
$target_env = NULL;
}
if (!$target_env) {
$environments = environment_load();
$options = array();
foreach ($environments as $name => $env) {
$options[$name] = environment_drush_render_environment($env);
}
$target_env = drush_choice($options);
}
if (!$target_env) {
return;
}
$force = drush_get_option('force');
$no_cache_clear = drush_get_option('nocacheclear', FALSE);
drush_print(dt("Switching the environment to !environment", array(
'!environment' => $target_env,
)));
if (!drush_get_context('DRUSH_SIMULATE')) {
$result = environment_switch($target_env, $force, !$no_cache_clear);
}
else {
$result = TRUE;
}
if ($result) {
drupal_set_message('Done.', 'success');
}
else {
drupal_set_message('Failed.', 'error');
}
}