Skip to content

Commit

Permalink
Adding $pluginPaths support to PluginTask
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 11, 2009
1 parent 8ca30f2 commit 62199db
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
35 changes: 33 additions & 2 deletions cake/console/libs/tasks/plugin.php
Expand Up @@ -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
*
Expand All @@ -52,6 +54,7 @@ class PluginTask extends Shell {
function initialize() {
$this->path = APP . 'plugins' . DS;
}

/**
* Execution method always used for tasks
*
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand Down
26 changes: 24 additions & 2 deletions cake/tests/cases/console/libs/tasks/plugin.test.php
Expand Up @@ -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
*
Expand All @@ -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');
Expand All @@ -113,5 +134,6 @@ function testBakeFoldersAndFiles() {

@rmdir(TMP . 'bake_test_plugin');
}

}
?>

0 comments on commit 62199db

Please sign in to comment.