Revision
576
Author
izi
Date
2008-08-22 06:00:32 -0700 (Fri, 22 Aug 2008)

Log Message

backported changes and bug fixes from PEAR1 Console_CommandLine

Modified Paths

Added Paths

Diff

Modified: sandbox/Console_CommandLine/trunk/package.xml (575 => 576)


--- sandbox/Console_CommandLine/trunk/package.xml	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/package.xml	2008-08-22 13:00:32 UTC (rev 576)
@@ -117,6 +117,11 @@
     <file role="test" name="console_commandline_parse_14.phpt"/>
     <file role="test" name="console_commandline_parse_15.phpt"/>
     <file role="test" name="console_commandline_parse_16.phpt"/>
+    <file role="test" name="console_commandline_parse_17.phpt"/>
+    <file role="test" name="console_commandline_parse_18.phpt"/>
+    <file role="test" name="console_commandline_webrequest_1.phpt"/>
+    <file role="test" name="console_commandline_webrequest_2.phpt"/>
+    <file role="test" name="console_commandline_webrequest_3.phpt"/>
     <file role="test" name="test.xml"/>
     <file role="test" name="tests.inc.php"/>
    </dir>
@@ -125,7 +130,7 @@
  <dependencies>
   <required>
    <php>
-    <min>5.2.0</min>
+    <min>5.3.0</min>
    </php>
    <pearinstaller>
     <min>2.0.0a1</min>

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Callback.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Callback.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Callback.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the Callback action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Counter.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Counter.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Counter.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the Version action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Help.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Help.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Help.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the Help action, a special action that displays the
  * help message, telling the user how to use the program.

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Password.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Password.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Password.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the Password action, a special action that allow the 
  * user to specify the password on the commandline or to be prompted for 

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreArray.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreArray.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreArray.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the StoreArray action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreFalse.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreFalse.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreFalse.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the StoreFalse action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreFloat.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreFloat.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreFloat.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the StoreFloat action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreInt.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreInt.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreInt.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the StoreInt action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreString.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreString.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreString.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the StoreString action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreTrue.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreTrue.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/StoreTrue.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the StoreTrue action.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Version.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Version.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Action/Version.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Action.php';
-
 /**
  * Class that represent the Version action, a special action that displays the
  * version string of the program.

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Argument.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Argument.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Argument.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Element.php';
-
 /**
  * Class that represent a command line argument.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Command.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Command.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Command.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine.php';
-
 /**
  * Class that represent a command with option and arguments.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Exception.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Exception.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Exception.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'PEAR/Exception.php';
-
 /**
  * Class for exceptions raised by the PEAR2_Console_CommandLine package.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/MessageProvider/Default.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/MessageProvider/Default.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/MessageProvider/Default.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,7 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/MessageProvider.php';
 
 /**
  * Lightweight class that manages messages used by PEAR2_Console_CommandLine package, 
@@ -49,13 +48,13 @@
      * @access protected
      */
     protected $messages = array(
-        'OPTION_VALUE_REQUIRED'   => 'option "{$name}" require a value.',
-        'OPTION_VALUE_UNEXPECTED' => 'option "{$name}" does not expects a value (got "{$value}").',
-        'OPTION_VALUE_NOT_VALID'  => 'option "{$name}" must be one of the following: "{$choices}" (got "{$value}").',
-        'OPTION_VALUE_TYPE_ERROR' => 'option "{$name}" require a value of type {$type} (got "{$value}").',
-        'OPTION_AMBIGUOUS'        => 'ambiguous option "{$name}", can be one of the following: {$matches}.',
-        'OPTION_UNKNOWN'          => 'unknown option "{$name}".',
-        'ARGUMENT_REQUIRED'       => 'you must provide at least {$argnum} argument{$plural}.',
+        'OPTION_VALUE_REQUIRED'   => 'Option "{$name}" requires a value.',
+        'OPTION_VALUE_UNEXPECTED' => 'Option "{$name}" does not expect a value (got "{$value}").',
+        'OPTION_VALUE_NOT_VALID'  => 'Option "{$name}" must be one of the following: "{$choices}" (got "{$value}").',
+        'OPTION_VALUE_TYPE_ERROR' => 'Option "{$name}" requires a value of type {$type} (got "{$value}").',
+        'OPTION_AMBIGUOUS'        => 'Ambiguous option "{$name}", can be one of the following: {$matches}.',
+        'OPTION_UNKNOWN'          => 'Unknown option "{$name}".',
+        'ARGUMENT_REQUIRED'       => 'You must provide at least {$argnum} argument{$plural}.',
         'PROG_HELP_LINE'          => 'Type "{$progname} -h" to get help.',
         'PROG_VERSION_LINE'       => '{$progname} version {$version}.',
         'COMMAND_HELP_LINE'       => 'Type "{$progname} <command> -h" to get help on specific command.',

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Option.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Option.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Option.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,9 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine.php';
-// require_once 'Console/CommandLine/Element.php';
-
 /**
  * Class that represent a commandline option.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Outputter/Default.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Outputter/Default.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Outputter/Default.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,7 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Outputter.php';
 
 /**
  * PEAR2_Console_CommandLine default Outputter.
@@ -49,7 +48,11 @@
      */
     public function stdout($msg)
     {
-        fwrite(STDOUT, $msg);
+        if (defined('STDOUT')) {
+            fwrite(STDOUT, $msg);
+        } else {
+            echo $msg;
+        }
     }
 
     // }}}
@@ -65,7 +68,11 @@
      */
     public function stderr($msg)
     {
-        fwrite(STDERR, $msg);
+        if (defined('STDERR')) {
+            fwrite(STDERR, $msg);
+        } else {
+            echo $msg;
+        }
     }
 
     // }}}

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Renderer/Default.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Renderer/Default.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/Renderer/Default.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine/Renderer.php';
-
 /**
  * PEAR2_Console_CommandLine default renderer.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine/XmlParser.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine/XmlParser.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine/XmlParser.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -21,8 +21,6 @@
  * @since     File available since release 0.1.0
  */
 
-// require_once 'Console/CommandLine.php';
-
 /**
  * Parser for command line xml definitions.
  *

Modified: sandbox/Console_CommandLine/trunk/src/Console/CommandLine.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/src/Console/CommandLine.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/src/Console/CommandLine.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -251,8 +251,12 @@
     {
         if (isset($params['name'])) {
             $this->name = $params['name'];
-        } else {
+        } else if (isset($argv) && count($argv) > 0) {
+            $this->name = $argv[0];
+        } else if (isset($_SERVER['argv']) && count($_SERVER['argv']) > 0) {
             $this->name = $_SERVER['argv'][0];
+        } else if (isset($_SERVER['SCRIPT_NAME'])) {
+            $this->name = basename($_SERVER['SCRIPT_NAME']);
         }
         if (isset($params['description'])) {
             $this->description = $params['description'];
@@ -320,7 +324,6 @@
      *
      * Example:
      * <code>
-     * require_once 'Console/CommandLine.php';
      * $parser = PEAR2_Console_CommandLine::fromXmlFile('path/to/file.xml');
      * $result = $parser->parse();
      * </code>
@@ -344,7 +347,6 @@
      *
      * Example:
      * <code>
-     * require_once 'Console/CommandLine.php';
      * $xmldata = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
      * <command>
      *   <description>Compress files</description>
@@ -663,9 +665,6 @@
      * // and in the result we will have:
      * // $result->options['range']: array(1, 5)
      *
-     * require_once 'Console/CommandLine.php';
-     * require_once 'Console/CommandLine/Action.php';
-     *
      * class ActionRange extends PEAR2_Console_CommandLine_Action
      * {
      *     public function execute($value=false, $params=array())
@@ -754,52 +753,39 @@
      * @access public
      * @throws Exception on user errors
      */
-    public function parse($userArgc=null, $userArgv=null, $beginAt=0)
+    public function parse($userArgc=null, $userArgv=null)
     {
-        // add "auto" options help and version if needed
-        if ($this->add_help_option) {
-            $this->addOption('help', array(
-                'short_name'  => '-h',    
-                'long_name'   => '--help',
-                'description' => 'show this help message and exit',
-                'action'      => 'Help'   
-            ));
+        $this->addBuiltinOptions();
+        if ($userArgc !== null && $userArgv !== null) {
+            $argc = $userArgc;
+            $argv = $userArgv;
+        } else {
+            list($argc, $argv) = $this->getArgcArgv();
         }
-        if ($this->add_version_option && !empty($this->version)) {
-            $this->addOption('version', array(
-                'long_name'   => '--version',
-                'description' => 'show the program version and exit',
-                'action'      => 'Version'   
-            ));
+        // build an empty result
+        include_once 'Console/CommandLine/Result.php';
+        $result = new PEAR2_Console_CommandLine_Result();
+        if (!$argc || empty($argv)) {
+            return $result;
         }
-        $argc = ($userArgc === null) ?
-            (isset($argc) ? $argc : $_SERVER['argc']) : $userArgc;
-        $argv = ($userArgv === null) ?
-            (isset($argv) ? $argv : $_SERVER['argv']) : $userArgv;
-        // case of a subcommand, skip main program args
-        for ($i=0; $i<$beginAt; $i++) {
+        if (!($this instanceof PEAR2_Console_CommandLine_Command)) {
+            // remove script name if we're not in a subcommand
+            array_shift($argv);
             $argc--;
-            array_shift($argv);
         }
-        // remove script name
-        array_shift($argv);
-        $argc--;
         // will contain aruments
         $args = array();
-        // build an empty result
-        $result = new PEAR2_Console_CommandLine_Result();
         foreach ($this->options as $name=>$option) {
             $result->options[$name] = $option->default;
         }
         // parse command line tokens
-        $i = 0;
-        while (++$i && $argc--) {
+        while ($argc--) {
             $token = array_shift($argv);
             try {
                 if (isset($this->commands[$token])) {
                     $result->command_name = $token;
-                    $result->command      = $this->commands[$token]->parse(null,
-                        null, $i);
+                    $result->command      = $this->commands[$token]->parse($argc,
+                        $argv);
                     break;
                 } else {
                     $this->parseToken($token, $result, $args, $argc);
@@ -1002,6 +988,96 @@
     }
 
     // }}}
+    // addBuiltinOptions() {{{
+
+    /**
+     * Add the builtin "Help" and "Version" options if needed.
+     *
+     * @return void
+     * @access protected 
+     */
+    public function addBuiltinOptions()
+    {
+        if ($this->add_help_option) {
+            $helpOptionParams = array(
+                'long_name'   => '--help',
+                'description' => 'show this help message and exit',
+                'action'      => 'Help'   
+            );
+            if (!$this->findOption('-h')) {
+                // short name is available, take it
+                $helpOptionParams['short_name'] = '-h';
+            }
+            $this->addOption('help', $helpOptionParams);
+        }
+        if ($this->add_version_option && !empty($this->version)) {
+            $versionOptionParams = array(
+                'long_name'   => '--version',
+                'description' => 'show the program version and exit',
+                'action'      => 'Version'   
+            );
+            if (!$this->findOption('-v')) {
+                // short name is available, take it
+                $versionOptionParams['short_name'] = '-v';
+            }
+            $this->addOption('version', $versionOptionParams);
+        }
+    } 
+
+    // }}}
+    // getArgcArgv() {{{
+
+    /**
+     * Try to return an array containing argc and argv, or trigger an error
+     * if it fails to get them.
+     *
+     * @return array
+     * @access protected
+     * @throws Exception 
+     */
+    protected function getArgcArgv()
+    {
+        if (php_sapi_name() != 'cli') {
+            // we have a web request
+            $argv = array($this->name);
+            if (isset($_REQUEST)) {
+                foreach ($_REQUEST as $key => $value) {
+                    if (!is_array($value)) {
+                        $value = array($value);
+                    }
+                    $opt = $this->findOption($key);
+                    if ($opt instanceof PEAR2_Console_CommandLine_Option) {
+                        // match a configured option
+                        $argv[] = $opt->short_name ? 
+                            $opt->short_name : $opt->long_name;
+                        foreach($value as $v) {
+                            if ($opt->expectsArgument()) {
+                                $argv[] = isset($_GET[$key]) ? urldecode($v) : $v;
+                            } else if ($v == '0' || $v == 'false') {
+                                array_pop($argv);
+                            }
+                        }
+                    } else if (isset($this->args[$key])) {
+                        // match a configured argument
+                        foreach($value as $v) {
+                            $argv[] = isset($_GET[$key]) ? urldecode($v) : $v;
+                        }
+                    }
+                }
+            }
+            return array(count($argv), $argv);
+        }
+        if (isset($argc) && isset($argv)) {
+            // case of register_argv_argc = 1
+            return array($argc, $argv);
+        }
+        if (isset($_SERVER['argc']) && isset($_SERVER['argv'])) {
+            return array($_SERVER['argc'], $_SERVER['argv']);
+        }
+        return array(0, array());
+    }
+
+    // }}}
     // _dispatchAction() {{{
 
     /**

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_13.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_13.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_13.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (user errors 1).
+Test for Console_CommandLine::parse() method (user errors 1).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,7 +7,7 @@
 --FILE--
 <?php
 
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 $parser = buildParser1();
 try {
@@ -18,4 +18,4 @@
 
 ?>
 --EXPECT--
-option "float" require a value of type float (got "foo").
+Option "float" requires a value of type float (got "foo").

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_14.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_14.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_14.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (user errors 2).
+Test for Console_CommandLine::parse() method (user errors 2).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,7 +7,7 @@
 --FILE--
 <?php
 
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 $parser = buildParser1();
 try {
@@ -18,4 +18,4 @@
 
 ?>
 --EXPECT--
-option "int" require a value of type int (got "foo").
+Option "int" requires a value of type int (got "foo").

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_15.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_15.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_15.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (subcommand error).
+Test for Console_CommandLine::parse() method (subcommand error).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,7 +7,7 @@
 --FILE--
 <?php
 
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 $parser = buildParser2();
 try {
@@ -18,6 +18,6 @@
 
 ?>
 --EXPECT--
-Error: you must provide at least 1 argument.
+Error: You must provide at least 1 argument.
 Type "some_program -h" to get help.
 Type "some_program <command> -h" to get help on specific command.

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_16.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_16.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_16.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (user errors 3).
+Test for Console_CommandLine::parse() method (user errors 3).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,7 +7,7 @@
 --FILE--
 <?php
 
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 $parser = buildParser1();
 try {
@@ -18,4 +18,4 @@
 
 ?>
 --EXPECT--
-option "string" must be one of the following: "foo", "bar", "baz" (got "fooz").
+Option "string" must be one of the following: "foo", "bar", "baz" (got "fooz").

Added: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_17.phpt (0 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_17.phpt	                        (rev 0)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_17.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -0,0 +1,62 @@
+--TEST--
+Test for Console_CommandLine::parse() method (user argc/argv 1).
+--SKIPIF--
+<?php if(php_sapi_name()!='cli') echo 'skip'; ?>
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
+
+$argv = array('somename', '-t', '-f', '--float=1.2', 'foo', 'bar');
+$argc = count($argv);
+try {
+    $parser = buildParser1();
+    $result = $parser->parse($argc, $argv);
+    var_dump($result);
+} catch (Console_CommandLine_Exception $exc) {
+    $parser->displayError($exc->getMessage());
+}
+
+?>
+--EXPECT--
+object(PEAR2_Console_CommandLine_Result)#21 (4) {
+  ["options"]=>
+  array(11) {
+    ["true"]=>
+    bool(true)
+    ["false"]=>
+    bool(false)
+    ["int"]=>
+    int(1)
+    ["float"]=>
+    float(1.2)
+    ["string"]=>
+    NULL
+    ["counter"]=>
+    NULL
+    ["callback"]=>
+    NULL
+    ["array"]=>
+    NULL
+    ["password"]=>
+    NULL
+    ["help"]=>
+    NULL
+    ["version"]=>
+    NULL
+  }
+  ["args"]=>
+  array(2) {
+    ["simple"]=>
+    string(3) "foo"
+    ["multiple"]=>
+    array(1) {
+      [0]=>
+      string(3) "bar"
+    }
+  }
+  ["command_name"]=>
+  bool(false)
+  ["command"]=>
+  bool(false)
+}

Added: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_18.phpt (0 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_18.phpt	                        (rev 0)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_18.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -0,0 +1,58 @@
+--TEST--
+Test for Console_CommandLine::parse() method (user argc/argv 2).
+--SKIPIF--
+<?php if(php_sapi_name()!='cli') echo 'skip'; ?>
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
+
+$argv = array('somename', '-v', 'install', '-f', 'foo');
+$argc = count($argv);
+try {
+    $parser = buildParser2();
+    $result = $parser->parse($argc, $argv);
+    var_dump($result);
+} catch (PEAR2_Console_CommandLine_Exception $exc) {
+    $parser->displayError($exc->getMessage());
+}
+
+?>
+--EXPECT--
+object(PEAR2_Console_CommandLine_Result)#23 (4) {
+  ["options"]=>
+  array(4) {
+    ["verbose"]=>
+    bool(true)
+    ["logfile"]=>
+    NULL
+    ["help"]=>
+    NULL
+    ["version"]=>
+    NULL
+  }
+  ["args"]=>
+  array(0) {
+  }
+  ["command_name"]=>
+  string(7) "install"
+  ["command"]=>
+  object(PEAR2_Console_CommandLine_Result)#25 (4) {
+    ["options"]=>
+    array(2) {
+      ["force"]=>
+      bool(true)
+      ["help"]=>
+      NULL
+    }
+    ["args"]=>
+    array(1) {
+      ["package"]=>
+      string(3) "foo"
+    }
+    ["command_name"]=>
+    bool(false)
+    ["command"]=>
+    bool(false)
+  }
+}

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_2.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_2.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_2.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (--help).
+Test for Console_CommandLine::parse() method (--help).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,7 +7,7 @@
 --FILE--
 <?php
 
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 $parser = buildParser1();
 $parser->parse();
@@ -30,7 +30,7 @@
   -a ARRAY, --array=ARRAY           test the StoreArray action
   -p password, --password=password  test the Password action
   -h, --help                        show this help message and exit
-  --version                         show the program version and exit
+  -v, --version                     show the program version and exit
 
 Arguments:
   simple    test a simple argument

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_4.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_4.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_4.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (errors 1).
+Test for Console_CommandLine::parse() method (errors 1).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,8 +7,7 @@
 --FILE--
 <?php
 
-require_once 'Console/CommandLine.php' ;
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 try {
     $parser = buildParser1();
@@ -19,5 +18,5 @@
 
 ?>
 --EXPECT--
-Error: unknown option "-d".
+Error: Unknown option "-d".
 Type "some_program -h" to get help.

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_5.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_5.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_5.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (errors 2).
+Test for Console_CommandLine::parse() method (errors 2).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,8 +7,7 @@
 --FILE--
 <?php
 
-require_once 'Console/CommandLine.php' ;
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 try {
     $parser = buildParser1();
@@ -19,5 +18,5 @@
 
 ?>
 --EXPECT--
-Error: option "float" require a value.
+Error: Option "float" requires a value.
 Type "some_program -h" to get help.

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_6.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_6.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_6.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (errors 3).
+Test for Console_CommandLine::parse() method (errors 3).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -7,8 +7,7 @@
 --FILE--
 <?php
 
-require_once 'Console/CommandLine.php' ;
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 try {
     $parser = buildParser1();
@@ -19,5 +18,5 @@
 
 ?>
 --EXPECT--
-Error: you must provide at least 2 arguments.
+Error: You must provide at least 2 arguments.
 Type "some_program -h" to get help.

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_8.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_8.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_8.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -7,7 +7,6 @@
 --FILE--
 <?php
 
-require_once 'Console/CommandLine.php' ;
 require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 try {

Modified: sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_9.phpt (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_9.phpt	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_parse_9.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -1,5 +1,5 @@
 --TEST--
-Test for PEAR2_Console_CommandLine::parse() method (password option).
+Test for Console_CommandLine::parse() method (password option).
 --SKIPIF--
 <?php if(php_sapi_name()!='cli') echo 'skip'; ?>
 --ARGS--
@@ -9,9 +9,7 @@
 --FILE--
 <?php
 
-require_once 'Console/CommandLine.php' ;
-require_once 'Console/CommandLine/Argument.php' ;
-require_once __DIR__ . DIRECTORY_SEPARATOR . 'tests.inc.php';
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
 
 $parser = buildParser1();
 $result = $parser->parse();

Added: sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_1.phpt (0 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_1.phpt	                        (rev 0)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_1.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -0,0 +1,15 @@
+--TEST--
+Test for Console_CommandLine::parse() with a web request 1
+--GET--
+version=1
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
+
+$parser = buildParser1();
+$parser->parse();
+
+?>
+--EXPECT--
+some_program version 0.1.0.

Added: sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_2.phpt (0 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_2.phpt	                        (rev 0)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_2.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -0,0 +1,35 @@
+--TEST--
+Test for Console_CommandLine::parse() with a web request 2
+--GET--
+help
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
+
+$parser = buildParser1();
+$parser->parse();
+
+?>
+--EXPECT--
+Description of our parser goes here...
+
+Usage:
+  some_program [options] <simple> <multiple...>
+
+Options:
+  -t, --true                        test the StoreTrue action
+  -f, --false                       test the StoreFalse action
+  --int=INT                         test the StoreInt action
+  --float=FLOAT                     test the StoreFloat action
+  -s STRING, --string=STRING        test the StoreString action
+  -c, --counter                     test the Counter action
+  --callback=callback               test the Callback action
+  -a ARRAY, --array=ARRAY           test the StoreArray action
+  -p password, --password=password  test the Password action
+  -h, --help                        show this help message and exit
+  -v, --version                     show the program version and exit
+
+Arguments:
+  simple    test a simple argument
+  multiple  test a multiple argument

Added: sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_3.phpt (0 => 576)


--- sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_3.phpt	                        (rev 0)
+++ sandbox/Console_CommandLine/trunk/tests/console_commandline_webrequest_3.phpt	2008-08-22 13:00:32 UTC (rev 576)
@@ -0,0 +1,56 @@
+--TEST--
+Test for Console_CommandLine::parse() with a web request 3
+--POST--
+true=1&false=1&string=foo&int=3&float=4.0&callback=somestring&-a[]=foo&-a[]=bar&-a[]=baz&simple=foo&multiple=bar
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tests.inc.php';
+
+$parser = buildParser1();
+$result = $parser->parse();
+var_dump($result->options);
+var_dump($result->args);
+
+?>
+--EXPECT--
+array(11) {
+  ["true"]=>
+  bool(true)
+  ["false"]=>
+  bool(false)
+  ["int"]=>
+  int(3)
+  ["float"]=>
+  float(4)
+  ["string"]=>
+  string(3) "foo"
+  ["counter"]=>
+  NULL
+  ["callback"]=>
+  string(20) "foo__fbzrfgevat__bar"
+  ["array"]=>
+  array(3) {
+    [0]=>
+    string(3) "foo"
+    [1]=>
+    string(3) "bar"
+    [2]=>
+    string(3) "baz"
+  }
+  ["password"]=>
+  NULL
+  ["help"]=>
+  NULL
+  ["version"]=>
+  NULL
+}
+array(2) {
+  ["simple"]=>
+  string(3) "foo"
+  ["multiple"]=>
+  array(1) {
+    [0]=>
+    string(3) "bar"
+  }
+}

Modified: sandbox/Console_CommandLine/trunk/tests/tests.inc.php (575 => 576)


--- sandbox/Console_CommandLine/trunk/tests/tests.inc.php	2008-06-25 23:19:28 UTC (rev 575)
+++ sandbox/Console_CommandLine/trunk/tests/tests.inc.php	2008-08-22 13:00:32 UTC (rev 576)
@@ -20,10 +20,11 @@
 // ensure that errors will be printed
 error_reporting(E_ALL | E_STRICT);
 ini_set('display_errors',true);
+set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__). '/../src/');
 
 // uncomment this when package won't be in the SandBox anymore
 // $basedir = __DIR__ . '/../..';
-$basedir = __DIR__ . '/../../..';
+$basedir = dirname(__FILE__) . '/../../..';
 
 require_once $basedir . '/autoload.php';