function _drush_add_commandfiles

8.0.x _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
6.x _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
7.x _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
4.x _drush_add_commandfiles($searchpath, $phase = NULL)
5.x _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
master _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
8 calls to _drush_add_commandfiles()
drush_load_bootstrap_commandfile_at_path in includes/
Check to see if there is a bootstrap class available at the specified location; if there is, load it.
drush_pm_enable_validate in commands/pm/
Validate callback. Determine the modules and themes that the user would like enabled.
pmRequestUnitCase::testVersionParserContrib in tests/pmRequestUnitTest.php
Tests for pm_parse_version() with project versions.
pmRequestUnitCase::testVersionParserCore in tests/pmRequestUnitTest.php
Tests for pm_parse_version() with drupal version scheme for core.
pmRequestUnitCase::testVersionParserCoreSemVer in tests/pmRequestUnitTest.php
Tests for pm_parse_version() with semantic versioning.

... See full list


includes/, line 1500
The drush command engine.


function _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE) {
  static $evaluated = array();
  $needs_sort = FALSE;

  if (count($searchpath)) {
    if (!$reset) {
      // Assemble a cid specific to the bootstrap phase and searchpaths.
      // Bump $cf_version when making a change to a dev version of Drush
      // that invalidates the commandfile cache.
      $cf_version = 6;
      $cid = drush_get_cid('commandfiles-' . $phase, array(), array_merge($searchpath, array($cf_version)));
      $command_cache = drush_cache_get($cid);
      if (isset($command_cache->data)) {
        $cached_list = $command_cache->data;
        // If we want to temporarily ignore modules via 'ignored-modules',
        // then we need to take these out of the cache as well.
        foreach (drush_get_option_list('ignored-modules') as $ignored) {

    // Build a list of all of the modules to attempt to load.
    // Start with any modules deferred from a previous phase.
    $list = commandfiles_cache()->deferred();
    if (isset($cached_list)) {
      $list = array_merge($list, $cached_list);
    else {
      // Scan for drush command files; add to list for consideration if found.
      foreach (array_unique($searchpath) as $path) {
        if (is_dir($path)) {
          $nomask = array_merge(drush_filename_blacklist(), drush_get_option_list('ignored-modules'));
          $dmv = DRUSH_MAJOR_VERSION;
          $files = drush_scan_directory($path, "/\.drush($dmv|)\.inc$/", $nomask);
          foreach ($files as $filename => $info) {
            $module = basename($filename);
            $module = preg_replace('/\.*drush[0-9]*\.inc/', '', $module);
            // Only try to bootstrap modules that we have never seen before.
            if (!array_key_exists($module, $evaluated) && file_exists($filename)) {
              $evaluated[$module] = TRUE;
              $list[$module] = $filename;
      if (isset($cid)) {
        drush_cache_set($cid, $list);
    // Check to see if the commandfile is valid for this version of Drupal
    // and is still present on filesystem (in case of cached commandfile list).
    foreach ($list as $module => $filename) {
      // Only try to require if the file exists. If not, a file from the
      // command file cache may not be available anymore, in which case
      // we rebuild the cache for this phase.
      if (file_exists($filename)) {
        // Avoid realpath() here as Drush commandfiles can have phar:// locations.
        $load_command = commandfiles_cache()->add($filename);
        if ($load_command) {
          $needs_sort = TRUE;
      elseif (!$reset) {
        _drush_add_commandfiles($searchpath, $phase, TRUE);
        $needs_sort = FALSE;

    if ($needs_sort) {