From e9396e0441daa00fb1287ab9fdccdc5efd07934a Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 15 Sep 2006 23:42:47 +0000 Subject: update prado-cli.php --- framework/prado-cli.php | 114 ++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 56 deletions(-) (limited to 'framework') diff --git a/framework/prado-cli.php b/framework/prado-cli.php index 7dd197f3..8921d25b 100755 --- a/framework/prado-cli.php +++ b/framework/prado-cli.php @@ -2,10 +2,10 @@ run(new HtmlReporter()); -?>'; +?>'; } function render_functional_test_fixture() @@ -129,10 +129,10 @@ function create_directory($dir, $mask) { mkdir($dir); echo "creating $dir\n"; - } + } if(is_dir($dir)) chmod($dir, $mask); -} +} function create_file($filename, $content) { @@ -147,9 +147,10 @@ function render_index_file() { $framework = realpath(dirname(__FILE__)).'/prado.php'; return ' * @author Wei Zhuo */ -class ConsoleOptions -{ +class ConsoleOptions +{ private $_short_options; private $_long_options; private $_options; private $_args; private $_values; - + /** * @param array list of options with the following format * option['name'] = array('short', 'long', 'parameter', 'description') @@ -232,7 +234,7 @@ class ConsoleOptions $this->_options = $options; $this->_args = $args; } - + /** * The second parameter is a string of allowed short options. Each of the * option letters can be followed by a colon ':' to specify that the option @@ -243,7 +245,7 @@ class ConsoleOptions * leading '--' should not be included in the option name. Options that * require an argument should be followed by '=', and options that take an * option argument should be followed by '=='. - * + * * @param string $short_options specifies the list of allowed short options * @param array $long_options specifies the list of allowed long options */ @@ -252,7 +254,7 @@ class ConsoleOptions $this->_short_options = $short_options; $this->_long_options = $long_options; } - + /** * @return string list of options and its descriptions */ @@ -272,13 +274,13 @@ class ConsoleOptions $options[] = $details; $descriptions[] = $option[3]; } - + $content = ''; for($i = 0, $k = count($options); $i < $k; $i++) $content .= str_pad($options[$i],$max+3).$descriptions[$i]."\n"; return $content; } - + /** * @param string argument name * @return string argument value @@ -287,10 +289,10 @@ class ConsoleOptions { if(is_null($this->_values)) $this->_values = $this->getNamedOptions(); - + return isset($this->_values[$name]) ? $this->_values[$name] : null; } - + /** * @return array list of all options given. */ @@ -300,7 +302,7 @@ class ConsoleOptions $this->_values = $this->getNamedOptions(); return $this->_values; } - + /** * @return boolean true if one or more options are given. */ @@ -310,7 +312,7 @@ class ConsoleOptions $this->_values = $this->getNamedOptions(); return count($this->_values) > 0; } - + /** * Parse the options from args into named arguements. */ @@ -330,7 +332,7 @@ class ConsoleOptions } return $options; } - + /** * Gets the command-line options. * @@ -351,7 +353,7 @@ class ConsoleOptions */ public function parseOptions($args) { - if (empty($args)) + if (empty($args)) return array(array(), array()); $short_options = $this->_short_options; @@ -362,15 +364,15 @@ class ConsoleOptions settype($args, 'array'); - if ($long_options) + if ($long_options) sort($long_options); - if (isset($args[0]{0}) && $args[0]{0} != '-') + if (isset($args[0]{0}) && $args[0]{0} != '-') array_shift($args); reset($args); - - while (list($i, $arg) = each($args)) + + while (list($i, $arg) = each($args)) { /* The special element '--' means explicit end of @@ -381,14 +383,14 @@ class ConsoleOptions break; } - if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) + if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) { $non_opts = array_merge($non_opts, array_slice($args, $i)); break; - } - elseif (strlen($arg) > 1 && $arg{1} == '-') + } + elseif (strlen($arg) > 1 && $arg{1} == '-') $this->parseLongOption(substr($arg, 2), $long_options, $opts, $args); - else + else $this->parseShortOption(substr($arg, 1), $short_options, $opts, $args); } @@ -397,7 +399,7 @@ class ConsoleOptions private function parseShortOption($arg, $short_options, &$opts, &$args) { - for ($i = 0; $i < strlen($arg); $i++) + for ($i = 0; $i < strlen($arg); $i++) { $opt = $arg{$i}; $opt_arg = null; @@ -406,27 +408,27 @@ class ConsoleOptions if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') throw new Exception("Console_Getopt: unrecognized option -- $opt"); - if (strlen($spec) > 1 && $spec{1} == ':') + if (strlen($spec) > 1 && $spec{1} == ':') { - if (strlen($spec) > 2 && $spec{2} == ':') + if (strlen($spec) > 2 && $spec{2} == ':') { - if ($i + 1 < strlen($arg)) + if ($i + 1 < strlen($arg)) { /* Option takes an optional argument. Use the remainder of the arg string if there is anything left. */ $opts[] = array($opt, substr($arg, $i + 1)); break; } - } - else + } + else { /* Option requires an argument. Use the remainder of the arg string if there is anything left. */ - if ($i + 1 < strlen($arg)) + if ($i + 1 < strlen($arg)) { $opts[] = array($opt, substr($arg, $i + 1)); break; - } + } else if (list(, $opt_arg) = each($args)) /* Else use the next argument. */; else @@ -443,7 +445,7 @@ class ConsoleOptions @list($opt, $opt_arg) = explode('=', $arg); $opt_len = strlen($opt); - for ($i = 0; $i < count($long_options); $i++) + for ($i = 0; $i < count($long_options); $i++) { $long_opt = $long_options[$i]; $opt_start = substr($long_opt, 0, $opt_len); @@ -458,22 +460,22 @@ class ConsoleOptions options. */ if ($opt_rest != '' && $opt{0} != '=' && $i + 1 < count($long_options) && - $opt == substr($long_options[$i+1], 0, $opt_len)) + $opt == substr($long_options[$i+1], 0, $opt_len)) { throw new Exception("Console_Getopt: option --$opt is ambiguous"); } - if (substr($long_opt, -1) == '=') + if (substr($long_opt, -1) == '=') { - if (substr($long_opt, -2) != '==') + if (substr($long_opt, -2) != '==') { /* Long option requires an argument. Take the next argument if one wasn't specified. */; - if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) + if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) throw new Exception("Console_Getopt: option --$opt requires an argument"); } - } - else if ($opt_arg) + } + else if ($opt_arg) throw new Exception("Console_Getopt: option --$opt doesn't allow an argument"); $opts[] = array($opt, $opt_arg); -- cgit v1.2.3