]> granicus.if.org Git - php/commitdiff
Implement getopt2() method and keep BC for getopt().
authorAndrei Zmievski <andrei@php.net>
Thu, 11 Dec 2003 19:28:25 +0000 (19:28 +0000)
committerAndrei Zmievski <andrei@php.net>
Thu, 11 Dec 2003 19:28:25 +0000 (19:28 +0000)
pear/Console/Getopt.php
pear/package-Console_Getopt.xml

index 133a5bf3134ea213ba9a110fc7a319dc08aadb8a..52b2dea049ddf36bc4a1b993ae00f28bb103e22e 100644 (file)
@@ -63,7 +63,25 @@ class Console_Getopt {
      * @access public
      *
      */
+    function getopt2($args, $short_options, $long_options = null)
+    {
+        return Console_Getopt::doGetopt(2, $args, $short_options, $long_options);
+    }
+
+    /**
+     * This function expects $args to start with the script name (POSIX-style).
+     * Preserved for backwards compatibility.
+     * @see getopt2()
+     */    
     function getopt($args, $short_options, $long_options = null)
+    {
+        return Console_Getopt::doGetopt(1, $args, $short_options, $long_options);
+    }
+
+    /**
+     * The actual implementation of the argument parsing code.
+     */
+    function doGetopt($version, $args, $short_options, $long_options = null)
     {
         // in case you pass directly readPHPArgv() as the first arg
         if (PEAR::isError($args)) {
@@ -81,6 +99,16 @@ class Console_Getopt {
             sort($long_options);
         }
 
+        /*
+         * Preserve backwards compatibility with callers that relied on
+         * erroneous POSIX fix.
+         */
+        if ($version < 2) {
+            if (isset($args[0]{0}) && $args[0]{0} != '-') {
+                array_shift($args);
+            }
+        }
+
         reset($args);
         while (list($i, $arg) = each($args)) {
 
index 73738173c28e1cb80ceb6116305dfed778a9b14b..fa3275c2f3d337278a5270b48c5a805eb5ad3168 100644 (file)
@@ -23,9 +23,9 @@ short and long options.</description>
     </maintainer>
   </maintainers>
   <release>
-    <version>2.0</version>
-    <date>2003-12-06</date>
-    <notes>Revert of erroneous POSIX compatibility fix (BC break)</notes>
+    <version>1.2</version>
+    <date>2003-12-11</date>
+    <notes>Fix to preserve BC with 1.0 and allow correct behaviour for new users</notes>
     <state>stable</state>
     <filelist>
      <dir name="Console">
@@ -35,29 +35,40 @@ short and long options.</description>
   </release>
   <changelog>
     <release>
-      <version>0.11</version>
-      <date>2002-05-26</date>
-      <notes>POSIX getopt compatibility fix: treat first element of args
-        array as command name
-      </notes>
-      <state>beta</state>
+      <version>1.0</version>
+      <date>2002-09-13</date>
+      <notes>Stable release</notes>
+      <state>stable</state>
       <filelist>
         <dir name="Console">
           <file role="php" name="Getopt.php"/>
         </dir>
       </filelist>
     </release>
-    <release>
-      <version>0.10</version>
-      <date>2002-05-12</date>
-      <notes>Packaging fix</notes>
-      <state>beta</state>
-    </release>
-    <release>
-      <version>0.9</version>
-      <date>2002-05-12</date>
-      <notes>Initial release</notes>
-      <state>beta</state>
-    </release>
+   <release>
+     <version>0.11</version>
+     <date>2002-05-26</date>
+     <notes>POSIX getopt compatibility fix: treat first element of args
+       array as command name
+     </notes>
+     <state>beta</state>
+     <filelist>
+       <dir name="Console">
+         <file role="php" name="Getopt.php"/>
+       </dir>
+     </filelist>
+   </release>
+   <release>
+     <version>0.10</version>
+     <date>2002-05-12</date>
+     <notes>Packaging fix</notes>
+     <state>beta</state>
+   </release>
+   <release>
+     <version>0.9</version>
+     <date>2002-05-12</date>
+     <notes>Initial release</notes>
+     <state>beta</state>
+   </release>
   </changelog>
-</package>
+ </package>