updating shells with startup callback, so a shell initializes, then loads tasks, then starts up, Tasks are the same. few other minor fixes to bake, api and acl.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5239 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-06-04 07:21:17 +00:00
parent 52680ffcd3
commit 76a4ae2a79
6 changed files with 35 additions and 13 deletions

View file

@ -273,6 +273,7 @@ class ShellDispatcher {
if($command == 'help') { if($command == 'help') {
if(method_exists($shell, 'help')) { if(method_exists($shell, 'help')) {
$shell->startup();
$shell->help(); $shell->help();
exit(); exit();
} else { } else {
@ -285,6 +286,7 @@ class ShellDispatcher {
$this->shiftArgs(); $this->shiftArgs();
$shell->{$task}->initialize(); $shell->{$task}->initialize();
$shell->{$task}->loadTasks(); $shell->{$task}->loadTasks();
$shell->{$task}->startup();
$shell->{$task}->execute(); $shell->{$task}->execute();
return; return;
} }
@ -311,10 +313,14 @@ class ShellDispatcher {
} }
if($missingCommand && method_exists($shell, 'main')) { if($missingCommand && method_exists($shell, 'main')) {
$this->args = am(array($command), $this->args);
$shell->startup();
$shell->main(); $shell->main();
} else if($missingCommand && method_exists($shell, 'help')) { } else if($missingCommand && method_exists($shell, 'help')) {
$shell->startup();
$shell->help(); $shell->help();
} else if(!$privateMethod && method_exists($shell, $command)) { } else if(!$privateMethod && method_exists($shell, $command)) {
$shell->startup();
$shell->{$command}(); $shell->{$command}();
} else { } else {
$this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n"); $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'cake {$this->shell} help'.\n\n");

View file

@ -57,10 +57,10 @@ class AclShell extends Shell {
*/ */
var $tasks = array('DbConfig'); var $tasks = array('DbConfig');
/** /**
* override intialize of the Shell * override startup of the Shell
* *
*/ */
function initialize () { function startup() {
$this->dataSource = 'default'; $this->dataSource = 'default';
if (isset($this->params['datasource'])) { if (isset($this->params['datasource'])) {
@ -81,8 +81,10 @@ class AclShell extends Shell {
} }
if($this->command && !in_array($this->command, array('help'))) { if($this->command && !in_array($this->command, array('help'))) {
if(!file_exists(CONFIGS.'database.php')) { if(!config('database')) {
$this->DbConfig->execute(); $this->out("Your database configuration was not found. Take a moment to create one.\n");
$this->args = null;
return $this->DbConfig->execute();
} }
require_once (CONFIGS.'database.php'); require_once (CONFIGS.'database.php');

View file

@ -65,11 +65,10 @@ class ApiShell extends Shell {
if (empty($this->args)) { if (empty($this->args)) {
return $this->help(); return $this->help();
} }
if (count($this->args) == 1 && in_array($this->args[0], array_keys($this->paths))) { if (count($this->args) == 1 && in_array($this->args[0], array_keys($this->paths))) {
$this->args[1] = $this->args[0]; $this->args[1] = $this->args[0];
} }
if (count($this->args) > 1) { if (count($this->args) > 1) {
$path = $this->args[0]; $path = $this->args[0];
$class = $this->args[1]; $class = $this->args[1];
@ -103,7 +102,7 @@ class ApiShell extends Shell {
Inflector::underscore($class), Inflector::underscore($class),
substr(Inflector::underscore($class), 0, strpos(Inflector::underscore($class), '_')) substr(Inflector::underscore($class), 0, strpos(Inflector::underscore($class), '_'))
); );
foreach($candidates as $candidate) { foreach($candidates as $candidate) {
$File =& new File($path . $candidate . '.php'); $File =& new File($path . $candidate . '.php');

View file

@ -38,8 +38,6 @@ class BakeShell extends Shell {
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View'); var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View');
function initialize() {}
function main() { function main() {
if(!is_dir(CONFIGS)) { if(!is_dir(CONFIGS)) {
@ -48,7 +46,8 @@ class BakeShell extends Shell {
if(!config('database')) { if(!config('database')) {
$this->out("Your database configuration was not found. Take a moment to create one.\n"); $this->out("Your database configuration was not found. Take a moment to create one.\n");
$this->DbConfig->execute(); $this->args = null;
return $this->DbConfig->execute();
} }
$this->out('Interactive Bake Shell'); $this->out('Interactive Bake Shell');
$this->hr(); $this->hr();

View file

@ -130,17 +130,27 @@ class Shell extends Object {
} }
if(!PHP5 && isset($this->args[0]) && low($this->command) == low(Inflector::variable($this->args[0]))) { if(!PHP5 && isset($this->args[0]) && low($this->command) == low(Inflector::variable($this->args[0]))) {
$dispatch->shiftArgs(); $dispatch->shiftArgs();
} }
$this->Dispatch =& $dispatch; $this->Dispatch =& $dispatch;
} }
/** /**
* Initializes the Shell * Initializes the Shell
* can be overriden in subclasses * acts as constructor for subclasses
* allows configuration of tasks prior to shell execution
* *
* @return void * @return void
*/ */
function initialize() { function initialize() {
$this->_loadModels(); $this->_loadModels();
}
/**
* Starts up the the Shell
* allows for checking and configuring prior to command or main execution
* can be overriden in subclasses
*
* @return void
*/
function startup() {
$this->_welcome(); $this->_welcome();
} }
/** /**

View file

@ -29,6 +29,12 @@
if(!class_exists('File')) { if(!class_exists('File')) {
uses('file'); uses('file');
} }
/**
* Task class for creating new project apps and plugins
*
* @package cake
* @subpackage cake.cake.console.libs.tasks
*/
class ProjectTask extends Shell { class ProjectTask extends Shell {
/** /**