From 62199dba59abbc4b4aa1a7ec0ebe24920363e593 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 10 Jun 2009 22:52:38 -0400 Subject: [PATCH] Adding $pluginPaths support to PluginTask --- cake/console/libs/tasks/plugin.php | 35 +++++++++++++++++-- .../cases/console/libs/tasks/plugin.test.php | 26 ++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/cake/console/libs/tasks/plugin.php b/cake/console/libs/tasks/plugin.php index db9c7bf75..3da7fbf51 100644 --- a/cake/console/libs/tasks/plugin.php +++ b/cake/console/libs/tasks/plugin.php @@ -37,6 +37,7 @@ class PluginTask extends Shell { * */ var $tasks = array('Model', 'Controller', 'View'); + /** * path to CONTROLLERS directory * @@ -44,6 +45,7 @@ class PluginTask extends Shell { * @access public */ var $path = null; + /** * initialize * @@ -52,6 +54,7 @@ class PluginTask extends Shell { function initialize() { $this->path = APP . 'plugins' . DS; } + /** * Execution method always used for tasks * @@ -79,7 +82,7 @@ class PluginTask extends Shell { $this->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath)); $this->_stop(); } else { - $this->__interactive($plugin); + return $this->__interactive($plugin); } } @@ -94,9 +97,10 @@ class PluginTask extends Shell { $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path)); } $this->{$task}->loadTasks(); - $this->{$task}->execute(); + return $this->{$task}->execute(); } } + $this->help(); } /** @@ -125,6 +129,11 @@ class PluginTask extends Shell { function bake($plugin) { $pluginPath = Inflector::underscore($plugin); + $pathOptions = Configure::read('pluginPaths'); + if (count($pathOptions) > 1) { + $this->findPath($pathOptions); + } + $this->hr(); $this->out(__("Plugin Name: ", true) . $plugin); $this->out(__("Plugin Directory: ", true) . $this->path . $pluginPath); @@ -178,6 +187,28 @@ class PluginTask extends Shell { return true; } + +/** + * find and change $this->path to the user selection + * + * @return void + **/ + function findPath($pathOptions) { + $valid = false; + $max = count($pathOptions); + while (!$valid) { + foreach ($pathOptions as $i => $option) { + $this->out($i + 1 .'. ' . $option); + } + $prompt = __('Choose a plugin path from the paths above.', true); + $choice = $this->in($prompt); + if (intval($choice) > 0 && intval($choice) <= $max) { + $valid = true; + } + } + $this->path = $pathOptions[$choice - 1]; + } + /** * Help * diff --git a/cake/tests/cases/console/libs/tasks/plugin.test.php b/cake/tests/cases/console/libs/tasks/plugin.test.php index feb11d965..4cb8b3d2a 100644 --- a/cake/tests/cases/console/libs/tasks/plugin.test.php +++ b/cake/tests/cases/console/libs/tasks/plugin.test.php @@ -74,6 +74,26 @@ class PluginTaskTest extends CakeTestCase { $this->Task->path = TMP; } +/** + * startCase methods + * + * @return void + **/ + function startCase() { + $this->_paths = $paths = Configure::read('pluginPaths'); + $this->_testPath = array_push($paths, TMP); + Configure::write('pluginPaths', $paths); + } + +/** + * endCase + * + * @return void + **/ + function endCase() { + Configure::write('pluginPaths', $this->_paths); + } + /** * tearDown method * @@ -90,9 +110,10 @@ class PluginTaskTest extends CakeTestCase { * @return void **/ function testBakeFoldersAndFiles() { - $this->Task->setReturnValueAt(0, 'in', 'y'); + $this->Task->setReturnValueAt(0, 'in', $this->_testPath); + $this->Task->setReturnValueAt(1, 'in', 'y'); $this->Task->bake('BakeTestPlugin'); - + $path = TMP . 'bake_test_plugin'; $this->assertTrue(is_dir($path), 'No plugin dir %s'); $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s'); @@ -113,5 +134,6 @@ class PluginTaskTest extends CakeTestCase { @rmdir(TMP . 'bake_test_plugin'); } + } ?> \ No newline at end of file