From 44af49ced618f44957d3a45de535b8ea602b2773 Mon Sep 17 00:00:00 2001
From: James Sansbury <james.sansbury@lullabot.com>
Date: Wed, 25 Jan 2012 16:11:26 -0500
Subject: [PATCH] Issue #1415754 by greg.1.anderson, q0rban: Set a drush error
 for missing command callbacks, and adding a test.

---
 includes/command.inc  |    8 ++++++--
 tests/commandTest.php |   11 +++++++++++
 tests/unit.drush.inc  |    6 +++++-
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/includes/command.inc b/includes/command.inc
index 55940ef..281b73e 100644
--- a/includes/command.inc
+++ b/includes/command.inc
@@ -347,8 +347,12 @@ function _drush_invoke_hooks($command, $args, $defined_in_commandfile = NULL) {
     if (($defined_in_commandfile . "_" == substr($hook . "_",0,strlen($defined_in_commandfile)+ 1))) {
       $default_command_hook = sprintf("drush_%s", $hook);
     }
-    drush_log(dt("No hook functions were found for !command.", array('!command' => $command)), 'warning');
-    drush_log(dt("The primary drush_invoke() hook for !command is !default_func().  Please implement this function.  Run with --show-invoke to see all available hooks.", array('!command' => $command, '!default_func' => $default_command_hook)), 'warning');
+    $dt_args = array(
+      '!command' => $command,
+      '!default_func' => $default_command_hook,
+    );
+    $message = "No hook functions were found for !command. The primary hook function is !default_func(). Please implement this function. Run with --show-invoke to see all available hooks.";
+    $return = drush_set_error('DRUSH_FUNCTION_NOT_FOUND', dt($message, $dt_args));
   }
   if (drush_get_option('show-invoke')) {
     // We show all available hooks up to and including the one that failed (or all, if there were no failures)
diff --git a/tests/commandTest.php b/tests/commandTest.php
index 7eda6d0..6e80cbc 100644
--- a/tests/commandTest.php
+++ b/tests/commandTest.php
@@ -46,4 +46,15 @@ class commandCase extends Drush_CommandTestCase {
     $include_path = dirname(__FILE__) . '/hooks/magic_help_alter';
     $this->drush('version', array(), array('include' => $include_path, 'pipe' => NULL, 'magic' => '1234', 'strict' => NULL));
   }
+
+  /**
+   * Assert that errors are thrown for commands with missing callbacks.
+   */
+  public function testMissingCommandCallback() {
+    $options = array(
+      'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
+      //'show-invoke' => TRUE,
+    );
+    $this->drush('missing-callback', array(), $options, NULL, NULL, self::EXIT_ERROR);
+  }
 }
diff --git a/tests/unit.drush.inc b/tests/unit.drush.inc
index f1cf569..54750c2 100644
--- a/tests/unit.drush.inc
+++ b/tests/unit.drush.inc
@@ -30,7 +30,11 @@ function unit_drush_command() {
   $items['unit-return-options'] = array(
     'description' => 'Return options as function result.',
     'bootstrap' => DRUSH_BOOTSTRAP_NONE,
-  );    
+  );
+  $items['missing-callback'] = array(
+    'description' => 'Command with no callback function, to test error reporting.',
+    'bootstrap' => DRUSH_BOOTSTRAP_NONE,
+  );
   return $items;
 }
 
-- 
1.7.7

