-/**
- * Return a list of possible drushrc file locations.
- *
- * @context
- * A valid drush context from drush_context_names().
- * @prefix
- * Optional. Specify a prefix to prepend to ".drushrc.php" when looking
- * for config files. Most likely used by contrib commands.
- * @return
- * An associative array containing possible config files to load
- * The keys are the 'context' of the files, the values are the file
- * system locations.
- */
-function _drush_config_file($context, $prefix = NULL, $version = '') {
- $configs = array();
- $base_name = 'drush' . $version . 'rc.php';
- $config_file = $prefix ? $prefix . '.' . $base_name : $base_name;
-
- // Did the user explicitly specify a config file?
- if ($config_list = (array)drush_get_context('DRUSH_CONFIG')) {
- foreach ($config_list as $config) {
- if (is_dir($config)) {
- $config = $config . '/' . $config_file;
- }
- $configs['custom'][] = $config;
- }
- }
-
- if ($drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT')) {
- $configs['drupal'] = array(
- $drupal_root . '/../drush/' . $config_file,
- $drupal_root . '/sites/all/drush/' . $config_file,
- $drupal_root . '/drush/' . $config_file,
- );
-
- if ($conf_path = drush_get_context('DRUSH_SELECTED_DRUPAL_SITE_CONF_PATH', 'sites/default')) {
- $site_path = $drupal_root . '/' . $conf_path;
- $configs['site'] = $site_path . "/" . $config_file;
- }
- }
-
- // in the user home directory
- $server_home = drush_server_home();
- if (isset($server_home)) {
- $configs['user'] = $server_home . '/.' . $config_file;
- }
-
- // in $HOME/.drush directory
- $per_user_config_dir = drush_get_context('DRUSH_PER_USER_CONFIGURATION');
- if (!empty($per_user_config_dir)) {
- $configs['home.drush'] = $per_user_config_dir . '/' . $config_file;
- }
-
- // In the system wide configuration folder.
- $configs['system'] = drush_get_context('DRUSH_SITE_WIDE_CONFIGURATION') . '/' . $config_file;
-
- // in the drush installation folder
- $configs['drush'] = dirname(__FILE__) . '/../' . $config_file;
-
- return empty($configs[$context]) ? '' : $configs[$context];
-}
-
-
-/**
- * Load drushrc files (if available) from several possible locations.
- */
-function drush_load_config($context) {
- drush_load_config_file($context, _drush_config_file($context));
- drush_load_config_file($context, _drush_config_file($context, '', DRUSH_MAJOR_VERSION));
-}
-
-function drush_load_config_file($context, $config_list) {
- foreach ((array)$config_list as $config) {
- if (file_exists($config)) {
- $options = $aliases = $command_specific = $override = array();
- drush_log(dt('Loading drushrc "!config" into "!context" scope.', array('!config' => realpath($config), '!context' => $context)), LogLevel::BOOTSTRAP);
- $ret = @include_once($config);
- if ($ret === FALSE) {
- drush_log(dt('Cannot open drushrc "!config", ignoring.', array('!config' => realpath($config))), LogLevel::WARNING);
- return FALSE;
- }
- if (!empty($options) || !empty($aliases) || !empty($command_specific) || !empty($override)) {
- $options = array_merge(drush_get_context($context), $options);
- $options['config-file'] = realpath($config);
-
- unset($options['site-aliases']);
- $options['command-specific'] = array_merge(isset($command_specific) ? $command_specific : array(), isset($options['command-specific']) ? $options['command-specific'] : array());
-
- drush_set_config_options($context, $options, $override);
- }
- }
- }
-}
-
-function drush_set_config_options($context, $options, $override = array()) {