? .svn
? drushrc.php
? z
? commands/core/.core.drush.inc.swp
? includes/.command.inc.swp
? includes/.drush.inc.swp
? includes/.environment.inc.swp
Index: commands/core/core.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/core.drush.inc,v
retrieving revision 1.2
diff -u -r1.2 core.drush.inc
--- commands/core/core.drush.inc	3 Apr 2009 15:44:35 -0000	1.2
+++ commands/core/core.drush.inc	6 Apr 2009 01:39:17 -0000
@@ -23,20 +23,16 @@
   $items = array();
 
   $items['help'] = array(
-    'callback' => 'drush_usage',
     'description' => 'Print this help message.',
     'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
   );
   $items['cron'] = array(
-    'callback' => 'core_cron_run',
     'description' => 'Run all cron hooks.',
   );
   $items['status'] = array(
-    'callback' => 'core_status',
     'description' => 'Provides a birds-eye view of the current Drupal installation, if any.',
   );
   $items['script'] = array(
-    'callback' => 'core_script',
     'description' => "Run php script(s).",
     'examples' => array(
       'drush script update_variables.php',
@@ -46,11 +42,9 @@
     ),
   );
   $items['cache clear'] = array(
-    'callback' => 'core_cache_clear',
     'description' => 'Clear all caches.'
   );
   $items['dl'] = array(
-    'callback' => 'core_dl',
     'description' => 'Download core Drupal and modules like Drush Extras.',
     'examples' => array(
       'drush dl drupal' => 'Download latest version of Drupal core.', 
@@ -67,7 +61,6 @@
     'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap at all.
   );
   $items['watchdog show'] = array(
-    'callback' => 'core_watchdog_show',
     'description' => 'Shows recent watchdog log messages. Optionally filter for a specific type.',
     'drupal dependencies' => drush_drupal_major_version() >= 6 ? array('dblog') : array('watchdog'),
     'arguments' => array(
@@ -82,7 +75,6 @@
     ),
   );
   $items['watchdog delete'] = array(
-    'callback' => 'core_watchdog_delete',
     'description' => 'Delete all messages or only those of a specified type.',
     'arguments' => array(
       'type' => 'The type of messages to delete. Use \'all.\' to do a complete wipe.',
@@ -95,7 +87,6 @@
     
   );
   $items['sync'] = array(
-    'callback' => 'core_sync',
     'description' => 'Rsync the Drupal tree to/from another server using ssh.',
     'arguments' => array(
       'source' => 'See rsync documentation.',
@@ -106,7 +97,6 @@
     ),
   );
   $items['eval'] = array(
-    'callback' => 'core_eval',
     'description' => 'Evaluate arbitrary php code after bootstrapping Drupal.',
     'examples' => array(
       'drush eval \"variable_set(\'hello\', \'world\');\"' => 'Sets the hello variable using Drupal API.',
@@ -118,6 +108,60 @@
   return $items;
 }
 
+
+/**
+ * This is called if no command or an unknown command is entered.
+ */
+function core_help() {
+  $commands = func_get_args();
+  drush_set_context('DRUSH_SHOWING_HELP', TRUE);
+  
+  if (empty($commands)) {
+    $phases = _drush_bootstrap_phases(); 
+    drush_print(dt('Usage: drush.php [options] <command> <command> ...'));
+    drush_print();
+    drush_print('Run "drush help [command]" to view command-specific help.');
+    drush_print(dt('Options: '));
+    foreach (drush_get_option_help() as $option => $description) {
+      $rows[] = array($option, $description);
+    }
+
+    drush_print_table($rows, 2);
+    drush_print();
+    drush_print('Commands: ');
+
+    $printed_rows = array();
+    $phase_index = DRUSH_BOOTSTRAP_DRUSH;
+
+    foreach ($phases as $phase_index) {
+      if ($phase_index > drush_get_context('DRUSH_BOOTSTRAP_PHASE')) {
+        drush_bootstrap($phase_index);
+      }
+      if (!drush_get_error()) {
+        $commands = drush_get_commands();
+        $rows = array();
+        foreach($commands as $key => $command) {
+          if (!array_key_exists($key, $printed_rows)) {
+            $rows[$key] = array(sprintf("%-20s", $key), $commands[$key]['description']);
+          }
+        }
+        drush_print_table($rows, 2);
+        $printed_rows = array_merge($printed_rows, $rows);
+      }
+      else {
+        break; 
+      }
+    }
+    return;
+  }
+  else {
+    return drush_show_help($commands);
+  }
+
+  drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt('Invalid command !command.', array('!command' => implode(" ", $commands))));
+}
+
+
 /**
  * Implementation of hook_drush_help().
  *
@@ -221,7 +265,7 @@
  * To print something to the terminal window, use drush_print().
  *
  */
-function core_cron_run() {
+function core_cron() {
   drupal_cron_run();
   drush_print(dt('Cron run successfully.'));
 }
Index: includes/command.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/command.inc,v
retrieving revision 1.21
diff -u -r1.21 command.inc
--- includes/command.inc	5 Apr 2009 22:39:17 -0000	1.21
+++ includes/command.inc	6 Apr 2009 01:39:18 -0000
@@ -137,26 +137,20 @@
     $part = implode(" ", $args);
     if (isset($implemented[$part])) {
       $command = $implemented[$part];
-      // We found a command descriptor, now we check if it is valid.
-      if (empty($command['callback'])) {
-        $command = FALSE;
-        break;
-      }
-      else {
-        // Normalize command descriptor
-        $command += array(
-          'command' => $part,
-          'description' => NULL,
-          'arguments' => array(),
-          'options' => array(),
-          'extras' => array(),
-          'core' => array(),
-          'scope' => 'site',
-          'bootstrap' => NULL,
-          'drupal dependencies' => array(),
-          'drush dependencies' => array(),
-        );
-      }
+      // Normalize command descriptor
+      $command += array(
+        'command' => $part,
+        'callback' => 'drush_command',
+        'description' => NULL,
+        'arguments' => array(),
+        'options' => array(),
+        'extras' => array(),
+        'core' => array(),
+        'scope' => 'site',
+        'bootstrap' => NULL,
+        'drupal dependencies' => array(),
+        'drush dependencies' => array(),
+      );
     }
     else {
       $arguments[] = array_pop($args);
@@ -178,6 +172,108 @@
 }
 
 /**
+ * Invoke drush api calls. 
+ * 
+ * Call the correct hook for all the modules that implement it. 
+ * Additionally, the ability to rollback when an error has been encountered is also provided.
+ * If at any point during execution, the drush_get_error() function returns anything but 0,
+ * drush_invoke() will trigger $hook_rollback for each of the hooks that implement it, 
+ * in reverse order from how they were executed.
+ *
+ * This function will also trigger pre_$hook and post_$hook variants of the hook 
+ * and it's rollbacks automatically.
+ *
+ * @param command 
+ *   The drush command to execute.
+ * @return
+ *   A boolean specifying whether or not the command was successfully completed. 
+ * 
+ */
+function drush_invoke($command) {
+  drush_command_include($command);
+  $args = func_get_args();
+  array_shift($args);
+
+
+  $hook = str_replace(" ", "_", $command);
+  $functions = array();
+  // First we build a list of functions are about to execute
+  $variations = array($hook . "_validate", "pre_$hook", $hook, "post_$hook");
+  foreach ($variations as $var_hook) {
+    foreach (drush_command_implements($var_hook) as $name) {
+      $functions[] = $name . '_' . $var_hook;
+    }
+  }
+
+  $rollback = FALSE;
+  $completed = array();
+  foreach ($functions as $func) {
+    $completed[] = $func;
+    if (function_exists($func)) {
+      call_user_func_array($func, $args);
+      _drush_log_drupal_messages();
+      if (drush_get_error()) {
+        drush_log(dt('An error occurred at function : @func', array('@func' => $func)), 'error');
+        # As soon as an error occurs, roll back
+        $rollback = TRUE;
+        break;
+      }
+    }
+  }
+
+  // something went wrong, we need to undo 
+  if ($rollback) {
+    foreach (array_reverse($completed) as $func) {
+      $rb_func = $func . '_rollback';
+      if (function_exists($rb_func)) {
+        call_user_func_array($rb_func, $args);
+        _drush_log_drupal_messages();
+        drush_log("Changes for $func module have been rolled back.", 'rollback');
+      }
+    }
+  }
+
+  return !$rollback;
+}
+
+
+/**
+ * Entry point for commands into the drush_invoke API
+ *
+ * If a command does not have a callback specified, this function will be called.
+ *
+ * This function will trigger $hook_drush_init, then if no errors occur,
+ * it will call drush_invoke() with the command that was dispatch.
+ *
+ * If no errors have occured, it will run $hook_drush_exit.
+ */
+function drush_command() {
+  $args = func_get_args();
+  $command = drush_get_command();
+  foreach (drush_command_implements("drush_init") as $name) {
+    $func = $name . '_drush_init';
+    drush_log(dt("Initializing drush commandfile: !name", array('!name' => $name)), 'bootstrap');
+    call_user_func_array($func, $args);
+    _drush_log_drupal_messages();
+  }
+
+  if (!drush_get_error()) {
+    call_user_func_array('drush_invoke', 
+      array_merge(array($command['command']), $args));
+  }
+
+  if (!drush_get_error()) {
+    foreach (drush_command_implements('drush_exit') as $name) {
+      $func = $name . '_drush_exit';
+      call_user_func_array($func, $args);
+      _drush_log_drupal_messages();
+    }
+  }
+}
+
+
+
+/**
  * Invoke a hook in all available command files that implement it.
  *
  * @param $hook
@@ -312,40 +408,28 @@
 }
 
 /**
- * Storage mechanism for the cached commandfile list.
+ * Conditionally include files based on the command used.
  *
- * This function populates an internal static variable,
- * that contains the previously found command files.
+ * Steps through each of the currently loaded commandfiles and
+ * loads an optional commandfile based on the key.
  *
- * @param mixed
- *    Possible types :
- *      null - return the previous data only.
- *      array - replace the current cache contents with the contents of the array
- *      constant - when passed the DRUSH_FLUSH_COMMANDFILE_CACHE constant, this will wipe out the previous values, so future calls
- *                 to drush_command_file will automatically regenerate the cache.
- *  @return array
- *    The current file list that has been cached.
+ * When a command such as 'pm install' is called, this
+ * function will find all 'install.pm.inc' files that
+ * are present in each of the commandfile directories.
  */
-function _drush_commandfile_cache($list = null) {
-  static $cache = array();
-  if ($list === DRUSH_FLUSH_COMMANDFILE_CACHE) {
-    $cache = array();
-  }
-  elseif (!is_null($list)) {
-    $cache = $list;
+function drush_command_include($command) {
+  $parts = explode(' ', $command);
+  $command = implode(".", array_reverse($parts));
+ 
+  $commandfiles = drush_commandfile_list();
+  $options = array();
+  foreach ($commandfiles as $commandfile => $file) {
+    $filename = sprintf("%s/%s.inc", dirname($file), $command);
+    if (file_exists($filename)) {
+      drush_log(dt('Including !filename', array('!filename' => $filename)), 'bootstrap');
+      include_once($filename);
+    }
   }
-  return $cache;
-}
-
-/**
- * Flush the commandfile list cache.
- *
- * This is needed whenever drush code changes bootstrap level,
- * to allow additional information (such as commands in enabled modules)
- * to be retrieved.
- */
-function drush_commandfile_cache_flush() {
-  _drush_commandfile_cache(DRUSH_FLUSH_COMMANDFILE_CACHE);
 }
 
 /**
Index: includes/drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/drush.inc,v
retrieving revision 1.21
diff -u -r1.21 drush.inc
--- includes/drush.inc	3 Apr 2009 19:56:00 -0000	1.21
+++ includes/drush.inc	6 Apr 2009 01:39:19 -0000
@@ -147,58 +147,6 @@
 }
 
 /**
- * This is called if no command or an unknown command is entered.
- */
-function drush_usage() {
-  $commands = func_get_args();
-  drush_set_context('DRUSH_SHOWING_HELP', TRUE);
-  
-  if (empty($commands)) {
-    $phases = _drush_bootstrap_phases(); 
-    drush_print(dt('Usage: drush.php [options] <command> <command> ...'));
-    drush_print();
-    drush_print('Run "drush help [command]" to view command-specific help.');
-    drush_print(dt('Options: '));
-    foreach (drush_get_option_help() as $option => $description) {
-      $rows[] = array($option, $description);
-    }
-
-    drush_print_table($rows, 2);
-    drush_print();
-    drush_print('Commands: ');
-
-    $printed_rows = array();
-    $phase_index = DRUSH_BOOTSTRAP_DRUSH;
-
-    foreach ($phases as $phase_index) {
-      if ($phase_index > drush_get_context('DRUSH_BOOTSTRAP_PHASE')) {
-        drush_bootstrap($phase_index);
-      }
-      if (!drush_get_error()) {
-        $commands = drush_get_commands();
-        $rows = array();
-        foreach($commands as $key => $command) {
-          if (!array_key_exists($key, $printed_rows)) {
-            $rows[$key] = array(sprintf("%-20s", $key), $commands[$key]['description']);
-          }
-        }
-        drush_print_table($rows, 2);
-        $printed_rows = array_merge($printed_rows, $rows);
-      }
-      else {
-        break; 
-      }
-    }
-    return;
-  }
-  else {
-    return drush_show_help($commands);
-  }
-
-  drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt('Invalid command !command.', array('!command' => implode(" ", $commands))));
-}
-
-/**
  * Get the available options for Drush for use by help page.
  *
  * @return
Index: includes/environment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/environment.inc,v
retrieving revision 1.9
diff -u -r1.9 environment.inc
--- includes/environment.inc	5 Apr 2009 22:32:59 -0000	1.9
+++ includes/environment.inc	6 Apr 2009 01:39:19 -0000
@@ -350,9 +350,6 @@
 }
 
 
-
-
-
 /**
  * Returns the current working directory.
  *
? drush_pm/.svn
? drush_sql/.svn
? drush_tools/.svn
