From f861d685d50d9766ef8791c52fa58a894b059e95 Mon Sep 17 00:00:00 2001 From: gwoo Date: Sat, 18 Oct 2008 19:54:56 +0000 Subject: [PATCH] refactoring shell paths, also closes #5451, shell to return exit values git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7762 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/cake.php | 52 ++++++++++++++++++++--------------------- cake/libs/configure.php | 4 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cake/console/cake.php b/cake/console/cake.php index f94adc56a5a..ee95209945a 100644 --- a/cake/console/cake.php +++ b/cake/console/cake.php @@ -129,8 +129,7 @@ function __construct($args = array()) { $this->__initConstants(); $this->parseParams($args); $this->__initEnvironment(); - $this->dispatch(); - die("\n"); + exit($this->dispatch()); } /** * Defines core configuration. @@ -191,11 +190,29 @@ function __initEnvironment() { } $this->shiftArgs(); - $vendorPaths = Configure::read('vendorPaths'); - foreach ($vendorPaths as $path) { - $this->shellPaths[] = $path . 'shells' . DS; + + $paths = array(); + + $pluginPaths = Configure::read('pluginPaths'); + foreach ($pluginPaths as $pluginPath) { + $plugins = Configure::listObjects('plugin', $pluginPath); + foreach ((array)$plugins as $plugin) { + $path = $pluginPath . strtolower($plugin) . DS . 'vendors' . DS . 'shells' . DS; + if (file_exists($path)) { + $paths[] = $path; + } + } + } + + $vendorPaths = array_values(Configure::read('vendorPaths')); + foreach ($vendorPaths as $vendorPath) { + $path = rtrim($vendorPath, DS) . DS . 'shells' . DS; + if (file_exists($path)) { + $paths[] = $path; + } } - $this->shellPaths[] = CONSOLE_LIBS; + + $this->shellPaths = array_values(array_unique(array_merge($paths, Configure::read('shellPaths')))); } /** * Initializes the environment and loads the Cake core. @@ -262,22 +279,6 @@ function dispatch() { $this->help(); } else { $loaded = false; - $paths = array(); - - if ($plugin !== null) { - $pluginPaths = Configure::read('pluginPaths'); - $count = count($pluginPaths); - for ($i = 0; $i < $count; $i++) { - $paths[] = $pluginPaths[$i] . $plugin . DS . 'vendors' . DS . 'shells' . DS; - } - } - - $vendorPaths = array_values(Configure::read('vendorPaths')); - $count = count($vendorPaths); - - for ($i = 0; $i < $count; $i++) { - $paths[] = rtrim($vendorPaths[$i], DS) . DS . 'shells' . DS; - } foreach ($this->shellPaths as $path) { $this->shellPath = $path . $this->shell . ".php"; @@ -323,8 +324,7 @@ function dispatch() { $this->help(); } } - $shell->{$task}->execute(); - return; + return $shell->{$task}->execute(); } } @@ -353,11 +353,11 @@ function dispatch() { if ($missingCommand && method_exists($shell, 'main')) { $shell->startup(); - $shell->main(); + return $shell->main(); } elseif (!$privateMethod && method_exists($shell, $command)) { $this->shiftArgs(); $shell->startup(); - $shell->{$command}(); + return $shell->{$command}(); } else { $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n"); } diff --git a/cake/libs/configure.php b/cake/libs/configure.php index f88430117dc..ef34d163361 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -503,7 +503,7 @@ function corePaths($type = null) { $paths['cake'][] = $cake; $paths['class'][] = $cake; $paths['vendor'][] = $path . DS . 'vendors' . DS; - $paths['shell'][] = $path . DS . 'console' . DS . 'libs' . DS ; + $paths['shell'][] = $cake . 'console' . DS . 'libs' . DS; break; } } @@ -586,7 +586,7 @@ function buildPaths($paths) { 'plugin' => array(APP . 'plugins' . DS), 'vendor' => array(APP . 'vendors' . DS, VENDORS), 'locale' => array(APP . 'locale' . DS), - 'shell' => array(APP . 'vendors' . DS . 'shells' . DS) + 'shell' => array() ); foreach ($basePaths as $type => $default) {