Skip to content
Permalink
Browse files

Adding $pluginPaths support to PluginTask

  • Loading branch information...
markstory committed Jun 11, 2009
1 parent 8ca30f2 commit 62199dba59abbc4b4aa1a7ec0ebe24920363e593
Showing with 57 additions and 4 deletions.
  1. +33 −2 cake/console/libs/tasks/plugin.php
  2. +24 −2 cake/tests/cases/console/libs/tasks/plugin.test.php
@@ -37,13 +37,15 @@ class PluginTask extends Shell {
*
*/
var $tasks = array('Model', 'Controller', 'View');
/**
* path to CONTROLLERS directory
*
* @var array
* @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 @@ function execute() {
$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 @@ function execute() {
$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 @@ function __interactive($plugin = null) {
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 @@ function bake($plugin) {
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
*
@@ -74,6 +74,26 @@ function startTest() {
$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 @@ function endTest() {
* @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 @@ function testBakeFoldersAndFiles() {
@rmdir(TMP . 'bake_test_plugin');
}
}
?>

0 comments on commit 62199db

Please sign in to comment.
You can’t perform that action at this time.