mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 02:52:41 +00:00
Adding help function
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3456 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8cfaa0538b
commit
4df649dae5
2 changed files with 57 additions and 28 deletions
|
@ -29,26 +29,39 @@
|
|||
*/
|
||||
defineConstants();
|
||||
$cakeDir = CORE_PATH.DS.'cake'.DS;
|
||||
$argCount = count($argv);
|
||||
|
||||
if (count($argv) >= 2) {
|
||||
$appPath = getAppPath($cakeDir, $argv[1]);
|
||||
$taskName = '';
|
||||
$params = array();
|
||||
if ($argCount == 1 || $argv[1] == 'help') {
|
||||
showHelp();
|
||||
} else {
|
||||
$taskName = $argv[1];
|
||||
$appPath = false;
|
||||
$params = null;
|
||||
$showHelp = false;
|
||||
|
||||
if ($argCount > 2) {
|
||||
if ($argv[2] == 'help') {
|
||||
$showHelp = true;
|
||||
} else {
|
||||
$appPath = getAppPath($argv[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($appPath != false) {
|
||||
defineAppConstants($appPath);
|
||||
$taskName = $argv[2];
|
||||
$params = prepareParams($argv, 3);
|
||||
} else {
|
||||
defineAppConstantsWithDefaultValues();
|
||||
$taskName = $argv[1];
|
||||
$params = prepareParams($argv, 2);
|
||||
}
|
||||
|
||||
includeCoreFiles($cakeDir);
|
||||
executeTask($taskName, $params);
|
||||
} else {
|
||||
showHelp();
|
||||
|
||||
if ($showHelp) {
|
||||
showHelpForTask($taskName);
|
||||
} else {
|
||||
executeTask($taskName, $params);
|
||||
}
|
||||
}
|
||||
|
||||
function defineAppConstants($appPath) {
|
||||
|
@ -74,6 +87,25 @@
|
|||
}
|
||||
|
||||
function executeTask($taskName, $params) {
|
||||
$class = getTaskClass($taskName);
|
||||
$class->execute($params);
|
||||
}
|
||||
|
||||
function getAppPath($appPathShortcut) {
|
||||
$iniFile = CORE_PATH.DS.'apps.ini';
|
||||
|
||||
if (file_exists($iniFile)) {
|
||||
$appArray = readConfigFile($iniFile);
|
||||
|
||||
if (array_key_exists($appPathShortcut, $appArray)) {
|
||||
return $appArray[$appPathShortcut];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function getTaskClass($taskName) {
|
||||
$scriptDir = dirname(__FILE__);
|
||||
$taskPath = 'tasks'.DS.$taskName.'_task.php';
|
||||
require($scriptDir.DS.'tasks'.DS.'bake_task.php');
|
||||
|
@ -85,22 +117,7 @@
|
|||
}
|
||||
|
||||
$className = $taskName.'Task';
|
||||
$class = new $className;
|
||||
$class->execute($params);
|
||||
}
|
||||
|
||||
function getAppPath($cakeDir, $appPathShortcut) {
|
||||
$iniFile = $cakeDir.'config'.DS.'apps.ini';
|
||||
|
||||
if (file_exists($iniFile)) {
|
||||
$appArray = readConfigFile($iniFile);
|
||||
|
||||
if (array_key_exists($appPathShortcut, $appArray)) {
|
||||
return $appArray[$appPathShortcut];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return new $className;
|
||||
}
|
||||
|
||||
function includeCoreFiles($cakePath) {
|
||||
|
@ -139,4 +156,9 @@
|
|||
function showHelp() {
|
||||
echo "Usage: php bake2.php task [param1, ...]\n";
|
||||
}
|
||||
|
||||
function showHelpForTask($taskName) {
|
||||
$class = getTaskClass($taskName);
|
||||
$class->help();
|
||||
}
|
||||
?>
|
|
@ -26,6 +26,13 @@
|
|||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
class BakeTask {
|
||||
|
||||
}
|
||||
class BakeTask {
|
||||
|
||||
/**
|
||||
* Override this function in subclasses to provide a help message for your task.
|
||||
*/
|
||||
function help()
|
||||
{
|
||||
echo "There is no help available for the specified task.\n";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue