function _drush_find_commandfiles

8.0.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
6.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
7.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
3.x command.inc _drush_find_commandfiles($phase)
4.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
5.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
master command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
2 calls to _drush_find_commandfiles()
drush_bootstrap in includes/bootstrap.inc
Bootstrap Drush to the desired phase.
drush_command_belongs_to_disabled_module in ./drush.php
Check if the given command belongs to a disabled module

File

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

Code

function _drush_find_commandfiles($phase, $phase_max = FALSE) {
  if (!$phase_max) {
    $phase_max = $phase;
  }

  $searchpath = array();
  switch ($phase) {
    case DRUSH_BOOTSTRAP_DRUSH:
      // Core commands shipping with drush
      $searchpath[] = realpath(dirname(__FILE__) . '/../commands/');

      // User commands, specified by 'include' option
      if ($include = drush_get_context('DRUSH_INCLUDE', FALSE)) {
        foreach ($include as $path) {
          if (is_dir($path)) {
            drush_log('Include ' . $path, 'notice');
            $searchpath[] = $path;
          }
        }
      }

      // System commands, residing in $SHARE_PREFIX/share/drush/commands
      $share_path = drush_get_context('DRUSH_SITE_WIDE_COMMANDFILES');
      if (is_dir($share_path)) {
        $searchpath[] = $share_path;
      }

      // User commands, residing in ~/.drush
      $per_user_config_dir = drush_get_context('DRUSH_PER_USER_CONFIGURATION');
      if (!empty($per_user_config_dir)) {
        $searchpath[] = $per_user_config_dir;
      }

      // Include commandfiles located in Drupal's sites/all/drush even before root is bootstrapped.
      if ($drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT')) {
        $searchpath[] = $drupal_root . '/sites/all/drush';
      }
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_SITE:
      // If we are going to stop bootstrapping at the site, then
      // we will quickly add all commandfiles that we can find for
      // any module associated with the site, whether it is enabled
      // or not.  If we are, however, going to continue on to bootstrap
      // all the way to DRUSH_BOOTSTRAP_DRUPAL_FULL, then we will
      // instead wait for that phase, which will more carefully add
      // only those Drush command files that are associated with
      // enabled modules.
      if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_FULL) {
        $searchpath[] = conf_path() . '/modules';
        // Add all module paths, even disabled modules. Prefer speed over accuracy.
        $searchpath[] = 'sites/all/modules';
      }
      if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION) {
        // Too early for variable_get('install_profile', 'default'); look in all profiles.
        // If we're definitely going to get to DRUPAL_CONFIGURATION, then wait and
        // see if we have 'install_profile' available there.
        $searchpath[] = "profiles";
      }
      // Planning ahead for Drush scripts in core Drupal.
      if (drush_drupal_major_version() >= 8) {
        $searchpath[] = 'modules';
      }
      $searchpath[] = 'sites/all/themes';
      $searchpath[] = conf_path() . '/themes';
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION:
      // See comment above  regarding this if() condition.
      if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_FULL) {
        // You must define your install_profile in settings.php. The DB is not sufficient.
        // Drupal core does not yet do that. See http://drupal.org/node/545452.
        if ($profile = variable_get('install_profile', NULL)) {
          $searchpath[] = "profiles/$profile/modules";
        }
        else {
          // If 'install_profile' is not available, check all profiles.
          $searchpath[] = "profiles";
        }
      }
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_FULL:
      // Add enabled module paths. Since we are bootstrapped,
      // we can use the Drupal API.
      $ignored_modules = drush_get_option_list('ignored-modules', array());
      foreach (array_diff(module_list(), $ignored_modules) as $module) {
        $filename = drupal_get_filename('module', $module);
        if ($filename) {
          $searchpath[] = dirname($filename);
        }
      }
      break;
  }

  _drush_add_commandfiles($searchpath, $phase);
}