? drush.indy.patch
Index: drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush.inc,v
retrieving revision 1.16
diff -u -p -r1.16 drush.inc
--- drush.inc	19 May 2008 01:31:57 -0000	1.16
+++ drush.inc	18 Nov 2008 20:06:36 -0000
@@ -6,6 +6,9 @@
  * The drush API implementation and helpers.
  */
 
+// Load the drush module engine.
+require_once(dirname(__FILE__) . '/module.inc');
+
 /**
  * Dispatch a given set of commands.
  * Modules can add commands by implementing hook_drush_command().
@@ -50,7 +53,7 @@ function drush_get_commands($refresh = F
     return $commands;
   }
 
-  $commands = module_invoke_all('drush_command', TRUE);
+  $commands = drush_module_invoke_all('drush_command', TRUE);
 
   return $commands;
 }
Index: drush.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush.php,v
retrieving revision 1.24.2.3
diff -u -p -r1.24.2.3 drush.php
--- drush.php	18 Nov 2008 01:07:49 -0000	1.24.2.3
+++ drush.php	18 Nov 2008 20:06:36 -0000
@@ -243,16 +243,7 @@ function _drush_bootstrap_drupal() {
   // The bootstrap can fail silently, so we catch that in a shutdown function.
   register_shutdown_function('drush_shutdown');
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-  if (module_exists('drush')) {
-    require_once drupal_get_path('module', 'drush') . '/drush.inc';
-  }
-  else {
-    $message = "E: You must enable the Drush module for the site you want to use.\n";
-    $message .= "Hint: Drush was looking in the site '$conf_path'. You can select another site\n";
-    $message .= "with Drush enabled by specifying the Drupal URI to use with the --uri\n";
-    $message .= "parameter on the command line or \$options['uri'] in your drushrc.php file.\n";
-    die($message);
-  }
+  require_once dirname(__FILE__) . '/drush.inc';
 }
 
 function drush_shutdown() {
Index: module.inc
===================================================================
RCS file: module.inc
diff -N module.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ module.inc	18 Nov 2008 20:06:36 -0000
@@ -0,0 +1,104 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * The drush module engine.
+ *
+ * Closely follows the equivalent Drupal core functions.
+ *
+ */
+
+
+// Define the search pattern for drush modules.
+if (!defined(DRUSH_MODULE_PATTERN)) {
+  define(DRUSH_MODULE_PATTERN, '/drush_*/*.module');
+}
+
+/**
+ * Invoke a hook in all available modules that implement it.
+ *
+ * @param $hook
+ *   The name of the hook to invoke.
+ * @param ...
+ *   Arguments to pass to the hook.
+ * @return
+ *   An array of return values of the hook implementations. If modules return
+ *   arrays from their implementations, those are merged into one array.
+ */
+function drush_module_invoke_all() {
+  $args = func_get_args();
+  $hook = $args[0];
+  unset($args[0]);
+  $return = array();
+  foreach (drush_module_implements($hook) as $module) {
+    $function = $module .'_'. $hook;
+    $result = call_user_func_array($function, $args);
+    if (isset($result) && is_array($result)) {
+      $return = array_merge_recursive($return, $result);
+    }
+    else if (isset($result)) {
+      $return[] = $result;
+    }
+  }
+  return $return;
+}
+
+/**
+ * Determine which modules are implementing a hook.
+ *
+ * @param $hook
+ *   The name of the hook (e.g. "help" or "menu").
+ *
+ * @return
+ *   An array with the names of the modules which are implementing this hook.
+ */
+function drush_module_implements($hook) {
+  static $implementations;
+
+  if (!isset($implementations[$hook])) {
+    $implementations[$hook] = array();
+    $list = drush_module_list();
+    foreach ($list as $module) {
+      if (drush_module_hook($module, $hook)) {
+        $implementations[$hook][] = $module;
+      }
+    }
+  }
+  return (array)$implementations[$hook];
+}
+
+/**
+ * Collect a list of all available modules.
+ *
+ * @return
+ *   An associative array whose keys and values are the names of all available
+ *   modules.
+ */
+function drush_module_list() {
+  static $list = array();
+  if (empty($list)) {
+    require_once(dirname(__FILE__) . '/drush.module');
+    $list[] = 'drush';
+    foreach (glob(dirname(__FILE__) . DRUSH_MODULE_PATTERN) as $name) {
+      require_once($name);
+      $list[] = basename($name, '.module');
+    }
+  }
+  return $list;
+}
+
+/**
+ * Determine whether a module implements a hook.
+ *
+ * @param $module
+ *   The name of the module (without the .module extension).
+ * @param $hook
+ *   The name of the hook (e.g. "help" or "menu").
+ * @return
+ *   TRUE if the the hook is implemented.
+ */
+function drush_module_hook($module, $hook) {
+  return function_exists($module .'_'. $hook);
+}
+
