From c5e1a15f5a0d3b5428d64f1945efbff6b3976a3e Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Thu, 11 Oct 2007 04:11:50 +0000 Subject: [PATCH] A few tweaks to arguments and how they are handled. --- lib/Doctrine/Cli.php | 34 ++++++++++++++++++++++++++++------ lib/Doctrine/Cli/Task.php | 35 ----------------------------------- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/lib/Doctrine/Cli.php b/lib/Doctrine/Cli.php index a5299e832..44ad9b9e3 100644 --- a/lib/Doctrine/Cli.php +++ b/lib/Doctrine/Cli.php @@ -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() diff --git a/lib/Doctrine/Cli/Task.php b/lib/Doctrine/Cli/Task.php index 6f0158f63..52d9b83a4 100644 --- a/lib/Doctrine/Cli/Task.php +++ b/lib/Doctrine/Cli/Task.php @@ -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];