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

A few tweaks to arguments and how they are handled.

parent 26945749
......@@ -60,8 +60,7 @@ class Doctrine_Cli
$taskInstance = new $taskClass();
$taskInstance->taskName = str_replace('_', '-', Doctrine::tableize(str_replace('Doctrine_Cli_Task_', '', $taskName)));
$args = $taskInstance->prepareArgs($args);
$args = $this->prepareArgs($args);
$args = $this->prepareArgs($taskInstance, $args);
$taskInstance->validate($args);
......@@ -72,17 +71,40 @@ class Doctrine_Cli
}
}
protected function prepareArgs($args)
protected function prepareArgs($taskInstance, $args)
{
$args = array_values($args);
$prepared = array();
$requiredArguments = $taskInstance->getRequiredArguments();
foreach ($requiredArguments as $key => $arg) {
$prepared[$arg] = null;
}
$optionalArguments = $taskInstance->getOptionalArguments();
foreach ($optionalArguments as $key => $arg) {
$prepared[$arg] = null;
}
if (is_array($this->config) && !empty($this->config)) {
foreach ($this->config as $key => $value) {
if (array_key_exists($key, $args)) {
$args[$key] = $value;
if (array_key_exists($key, $prepared)) {
$prepared[$key] = $value;
}
}
}
return $args;
$copy = $args;
foreach ($prepared as $key => $value) {
if (!$value && !empty($copy)) {
$prepared[$key] = $copy[0];
unset($copy[0]);
$copy = array_values($copy);
}
}
return $prepared;
}
public function printTasks()
......
......@@ -55,41 +55,6 @@ abstract class Doctrine_Cli_Task
return true;
}
public function prepareArgs($args)
{
$args = array_values($args);
$prepared = array();
$requiredArguments = $this->getRequiredArguments();
$count = 0;
foreach ($requiredArguments as $key => $arg) {
if (isset($args[$count])) {
$prepared[$arg] = $args[$count];
} else {
$prepared[$arg] = null;
}
$count++;
}
$optionalArguments = $this->getOptionalArguments();
foreach ($optionalArguments as $key => $arg) {
if (isset($args[$count])) {
$prepared[$arg] = $args[$count];
} else {
$prepared[$arg] = null;
}
$count++;
}
$this->arguments = $prepared;
return $prepared;
}
public function getArgument($name)
{
return $this->arguments[$name];
......
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