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(method_exists($shell, 'help')) {
$shell->startup();
$shell->help();
exit();
} else {
@ -285,6 +286,7 @@ class ShellDispatcher {
$this->shiftArgs();
$shell->{$task}->initialize();
$shell->{$task}->loadTasks();
$shell->{$task}->startup();
$shell->{$task}->execute();
return;
}
@ -311,10 +313,14 @@ class ShellDispatcher {
}
if($missingCommand && method_exists($shell, 'main')) {
$this->args = am(array($command), $this->args);
$shell->startup();
$shell->main();
} else if($missingCommand && method_exists($shell, 'help')) {
$shell->startup();
$shell->help();
} else if(!$privateMethod && method_exists($shell, $command)) {
$shell->startup();
$shell->{$command}();
} else {
$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');
/**
* override intialize of the Shell
* override startup of the Shell
*
*/
function initialize () {
function startup() {
$this->dataSource = 'default';
if (isset($this->params['datasource'])) {
@ -81,8 +81,10 @@ class AclShell extends Shell {
}
if($this->command && !in_array($this->command, array('help'))) {
if(!file_exists(CONFIGS.'database.php')) {
$this->DbConfig->execute();
if(!config('database')) {
$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');

View file

@ -65,7 +65,6 @@ class ApiShell extends Shell {
if (empty($this->args)) {
return $this->help();
}
if (count($this->args) == 1 && in_array($this->args[0], array_keys($this->paths))) {
$this->args[1] = $this->args[0];
}

View file

@ -38,8 +38,6 @@ class BakeShell extends Shell {
var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View');
function initialize() {}
function main() {
if(!is_dir(CONFIGS)) {
@ -48,7 +46,8 @@ class BakeShell extends Shell {
if(!config('database')) {
$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->hr();

View file

@ -135,12 +135,22 @@ class Shell extends Object {
}
/**
* Initializes the Shell
* can be overriden in subclasses
* acts as constructor for subclasses
* allows configuration of tasks prior to shell execution
*
* @return void
*/
function initialize() {
$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();
}
/**

View file

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