Adding $pluginPaths support to PluginTask

This commit is contained in:
mark_story 2009-06-10 22:52:38 -04:00
parent 8ca30f2d22
commit 62199dba59
2 changed files with 57 additions and 4 deletions

View file

@ -37,6 +37,7 @@ class PluginTask extends Shell {
* *
*/ */
var $tasks = array('Model', 'Controller', 'View'); var $tasks = array('Model', 'Controller', 'View');
/** /**
* path to CONTROLLERS directory * path to CONTROLLERS directory
* *
@ -44,6 +45,7 @@ class PluginTask extends Shell {
* @access public * @access public
*/ */
var $path = null; var $path = null;
/** /**
* initialize * initialize
* *
@ -52,6 +54,7 @@ class PluginTask extends Shell {
function initialize() { function initialize() {
$this->path = APP . 'plugins' . DS; $this->path = APP . 'plugins' . DS;
} }
/** /**
* Execution method always used for tasks * 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->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath));
$this->_stop(); $this->_stop();
} else { } 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->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
} }
$this->{$task}->loadTasks(); $this->{$task}->loadTasks();
$this->{$task}->execute(); return $this->{$task}->execute();
} }
} }
$this->help();
} }
/** /**
@ -125,6 +129,11 @@ class PluginTask extends Shell {
function bake($plugin) { function bake($plugin) {
$pluginPath = Inflector::underscore($plugin); $pluginPath = Inflector::underscore($plugin);
$pathOptions = Configure::read('pluginPaths');
if (count($pathOptions) > 1) {
$this->findPath($pathOptions);
}
$this->hr(); $this->hr();
$this->out(__("Plugin Name: ", true) . $plugin); $this->out(__("Plugin Name: ", true) . $plugin);
$this->out(__("Plugin Directory: ", true) . $this->path . $pluginPath); $this->out(__("Plugin Directory: ", true) . $this->path . $pluginPath);
@ -178,6 +187,28 @@ class PluginTask extends Shell {
return true; 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 * Help
* *

View file

@ -74,6 +74,26 @@ class PluginTaskTest extends CakeTestCase {
$this->Task->path = TMP; $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 * tearDown method
* *
@ -90,7 +110,8 @@ class PluginTaskTest extends CakeTestCase {
* @return void * @return void
**/ **/
function testBakeFoldersAndFiles() { 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'); $this->Task->bake('BakeTestPlugin');
$path = TMP . 'bake_test_plugin'; $path = TMP . 'bake_test_plugin';
@ -113,5 +134,6 @@ class PluginTaskTest extends CakeTestCase {
@rmdir(TMP . 'bake_test_plugin'); @rmdir(TMP . 'bake_test_plugin');
} }
} }
?> ?>