diff options
author | wei <> | 2006-09-15 23:42:47 +0000 |
---|---|---|
committer | wei <> | 2006-09-15 23:42:47 +0000 |
commit | e9396e0441daa00fb1287ab9fdccdc5efd07934a (patch) | |
tree | 5ed3a7f01cef05b786be0154be9492417a815c87 /framework/prado-cli.php | |
parent | 2606b91b9f25799fc652aa1eba9dd6bcc32cfcbd (diff) |
update prado-cli.php
Diffstat (limited to 'framework/prado-cli.php')
-rwxr-xr-x | framework/prado-cli.php | 114 |
1 files changed, 58 insertions, 56 deletions
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 @@ <?php /** - * Prado command line developer tools. + * Prado command line developer tools. */ -if(!isset($_SERVER['argv'])) +if(!isset($_SERVER['argv'])) die('Must be run from the command line'); //command line options. @@ -32,7 +32,7 @@ Example: php prado-cli.php -c ./example1 EOD; } - + /** * Functions to create new prado project. */ @@ -41,29 +41,29 @@ function create_new_prado_project($dir) { if(strlen(trim($dir)) == 0) return; - + $rootPath = realpath(dirname(trim($dir))); - + $basePath = $rootPath.'/'.basename($dir); $assetPath = $basePath.'/assets'; $protectedPath = $basePath.'/protected'; - $runtimePath = $basePath.'/protected/runtime'; + $runtimePath = $basePath.'/protected/runtime'; $pagesPath = $protectedPath.'/pages'; $indexFile = $basePath.'/index.php'; $htaccessFile = $protectedPath.'/.htaccess'; $defaultPageFile = $pagesPath.'/Home.page'; - + $tests = $basePath.'/tests'; $unit_tests = $tests.'/unit'; $functional_tests = $tests.'/functional'; - + create_directory($basePath, 0755); create_directory($assetPath,0777); create_directory($protectedPath,0755); create_directory($runtimePath,0777); create_directory($pagesPath,0755); - + create_file($indexFile, render_index_file()); create_file($htaccessFile, render_htaccess_file()); create_file($defaultPageFile, render_default_page()); @@ -73,21 +73,21 @@ function create_test_fixtures($dir) { if(strlen(trim($dir)) == 0) return; - + $rootPath = realpath(dirname(trim($dir))); $basePath = $rootPath.'/'.basename($dir); - + $tests = $basePath.'/tests'; $unit_tests = $tests.'/unit'; $functional_tests = $tests.'/functional'; - + create_directory($tests,0755); create_directory($unit_tests,0755); create_directory($functional_tests,0755); - + $unit_test_index = $tests.'/unit.php'; $functional_test_index = $tests.'/functional.php'; - + create_file($unit_test_index, render_unit_test_fixture()); create_file($functional_test_index, render_functional_test_fixture()); } @@ -105,7 +105,7 @@ $test_cases = dirname(__FILE__)."/unit"; $tester = new PradoUnitTester($test_cases, $app_directory); $tester->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 '<?php +$frameworkPath=\''.$framework.'\'; +/** The directory checks may be removed if performance is required **/ $basePath=dirname(__FILE__); -$frameworkPath=\''.$framework.'\'; $assetsPath=$basePath."/assets"; $runtimePath=$basePath."/protected/runtime"; @@ -160,6 +161,7 @@ if(!is_writable($assetsPath)) if(!is_writable($runtimePath)) die("Please make sure that the directory $runtimePath is writable by Web server process."); + require_once($frameworkPath); $application=new TApplication; @@ -199,21 +201,21 @@ EOD; // +----------------------------------------------------------------------+ // // $Id$ - + /** * Command-line options parsing class. * * @author Andrei Zmievski <andrei@php.net> * @author Wei Zhuo <weizhuo[at]gmail[dot]com> */ -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 * <tt>option['name'] = array('short', 'long', 'parameter', 'description')</tt> @@ -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); |