From fa1d7da56e40c88dbe274e08e0e4bf0d7bf02c3a Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 22 Apr 2011 16:08:26 -0430 Subject: [PATCH] Making shells return help if a ConsoleException is catched, like when passing bad parameters --- lib/Cake/Console/ShellDispatcher.php | 39 ++++++++++++++++------------ 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 465b6d303..b14047ad2 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -171,25 +171,30 @@ class ShellDispatcher { $command = $this->args[0]; } - if ($Shell instanceof Shell) { - $Shell->initialize(); - $Shell->loadTasks(); - return $Shell->runCommand($command, $this->args); - } - $methods = array_diff(get_class_methods($Shell), get_class_methods('Shell')); - $added = in_array($command, $methods); - $private = $command[0] == '_' && method_exists($Shell, $command); + try { + if ($Shell instanceof Shell) { + $Shell->initialize(); + $Shell->loadTasks(); + return $Shell->runCommand($command, $this->args); + } + $methods = array_diff(get_class_methods($Shell), get_class_methods('Shell')); + $added = in_array($command, $methods); + $private = $command[0] == '_' && method_exists($Shell, $command); - if (!$private) { - if ($added) { - $this->shiftArgs(); - $Shell->startup(); - return $Shell->{$command}(); - } - if (method_exists($Shell, 'main')) { - $Shell->startup(); - return $Shell->main(); + if (!$private) { + if ($added) { + $this->shiftArgs(); + $Shell->startup(); + return $Shell->{$command}(); + } + if (method_exists($Shell, 'main')) { + $Shell->startup(); + return $Shell->main(); + } } + } catch(ConsoleException $e) { + $this->help(); + $this->_stop(1); } throw new MissingShellMethodException(array('shell' => $shell, 'method' => $arg)); }