Commit b005689e authored by Jonathan.Wage's avatar Jonathan.Wage

More changes to Cli system.

parent 4e877c52
...@@ -32,8 +32,13 @@ ...@@ -32,8 +32,13 @@
*/ */
class Doctrine_Cli class Doctrine_Cli
{ {
protected $tasks = array();
protected $scriptName = null;
public function run($args) public function run($args)
{ {
$this->scriptName = $args[0];
if (!isset($args[1])) { if (!isset($args[1])) {
echo $this->printTasks(); echo $this->printTasks();
return; return;
...@@ -64,25 +69,48 @@ class Doctrine_Cli ...@@ -64,25 +69,48 @@ class Doctrine_Cli
echo "\nAvailable Doctrine Command Line Interface Tasks\n"; echo "\nAvailable Doctrine Command Line Interface Tasks\n";
echo str_repeat('-', 40)."\n\n"; echo str_repeat('-', 40)."\n\n";
foreach ($tasks as $taskName) foreach ($tasks as $taskName)
{ {
$className = 'Doctrine_Cli_Task_' . $taskName; $className = 'Doctrine_Cli_Task_' . $taskName;
$taskInstance = new $className(); $taskInstance = new $className();
$taskInstance->taskName = str_replace('_', '-', Doctrine::tableize($taskName)); $taskInstance->taskName = str_replace('_', '-', Doctrine::tableize($taskName));
echo "Name: " . $taskInstance->getName() . "\n"; echo $taskInstance->getDescription() . "\n";
echo "Description: " . $taskInstance->getDescription() . "\n";
$syntax = "Syntax: ";
if ($requiredArguments = $taskInstance->getRequiredArguments()) { $syntax .= $this->scriptName . ' ' . $taskInstance->getTaskName();
echo "Required Arguments: " . implode(', ', $requiredArguments) . "\n";
if ($required = $taskInstance->getRequiredArguments()) {
$syntax .= ' <' . implode('> <', $required) . '>';
}
if ($optional = $taskInstance->getOptionalArguments()) {
$syntax .= ' <' . implode('> <', $optional) . '>';
} }
if ($optionalArguments = $taskInstance->getOptionalArguments()) { echo $syntax."\n";
echo "Optional Arguments: " . implode(', ', $taskInstance->getOptionalArguments()) . "\n";
$args = null;
if ($requiredArguments = $taskInstance->getRequiredArgumentsDescriptions()) {
foreach ($requiredArguments as $name => $description) {
$args .= '*' . $name . ' - ' . $description."\n";
}
}
if ($optionalArguments = $taskInstance->getOptionalArgumentsDescriptions()) {
foreach ($requiredArguments as $name => $description) {
$args .= $name . ' - ' . $description."\n";
}
} }
echo "Syntax: " . $taskInstance->getSyntax() . "\n"; if ($args) {
echo str_repeat('-', 40) . "\n\n"; echo "\nArguments:\n";
echo $args;
}
echo "\n".str_repeat("-", 40)."\n";
} }
} }
...@@ -115,6 +143,8 @@ class Doctrine_Cli ...@@ -115,6 +143,8 @@ class Doctrine_Cli
} }
} }
return $tasks; $this->tasks = array_merge($this->tasks, $tasks);
return $this->tasks;
} }
} }
\ No newline at end of file
...@@ -32,13 +32,13 @@ ...@@ -32,13 +32,13 @@
*/ */
abstract class Doctrine_Cli_Task abstract class Doctrine_Cli_Task
{ {
public $name = null, public $taskName = null,
$taskName = null,
$description = null, $description = null,
$arguments = array(),
$requiredArguments = array(), $requiredArguments = array(),
$optionalArguments = array(); $optionalArguments = array();
abstract function execute($args); abstract function execute();
public function validate($args) public function validate($args)
{ {
...@@ -81,12 +81,19 @@ abstract class Doctrine_Cli_Task ...@@ -81,12 +81,19 @@ abstract class Doctrine_Cli_Task
$count++; $count++;
} }
$this->arguments = $prepared;
return $prepared; return $prepared;
} }
public function getName() public function getArgument($name)
{
return $this->arguments[$name];
}
public function getArguments()
{ {
return $this->name; return $this->arguments;
} }
public function getTaskName() public function getTaskName()
...@@ -101,28 +108,36 @@ abstract class Doctrine_Cli_Task ...@@ -101,28 +108,36 @@ abstract class Doctrine_Cli_Task
public function getRequiredArguments() public function getRequiredArguments()
{ {
return $this->requiredArguments; return array_keys($this->requiredArguments);
} }
public function getOptionalArguments() public function getOptionalArguments()
{
return array_keys($this->optionalArguments);
}
public function getRequiredArgumentsDescriptions()
{
return $this->requiredArguments;
}
public function getOptionalArgumentsDescriptions()
{ {
return $this->optionalArguments; return $this->optionalArguments;
} }
public function getSyntax() public function getSyntax()
{ {
$taskName = $this->getTaskName(); $syntax = './cli ' . $this->getTaskName();
$requiredArguments = null;
$optionalArguments = null;
if ($required = $this->getRequiredArguments()) { if ($required = $this->getRequiredArguments()) {
$requiredArguments = '<' . implode('> <', $required) . '>'; $syntax .= ' <' . implode('> <', $required) . '>';
} }
if ($optional = $this->getOptionalArguments()) { if ($optional = $this->getOptionalArguments()) {
$optionalArguments = '<' . implode('> <', $optional) . '>'; $syntax .= ' <' . implode('> <', $optional) . '>';
} }
return './cli ' . $taskName . ' ' . $requiredArguments . ' ' . $optionalArguments; return $syntax;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment