cvs: php-src /pear System.php package-Console_Getopt.xml package-PEAR.xml /pear/Console Getopt.php /pear/scripts pearcmd.php
| From: | Greg Beaver | Date: | Thu, 11 Dec 2003 05:54:35 +0000 |
| Subject: | cvs: php-src /pear System.php package-Console_Getopt.xml package-PEAR.xml /pear/Console Getopt.php /pear/scripts pearcmd.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14781@lists.php.net to get a copy of this message | ||
cellog Thu Dec 11 00:54:35 2003 EDT
Modified files:
/php-src/pear/Console Getopt.php
/php-src/pear System.php package-Console_Getopt.xml
package-PEAR.xml
/php-src/pear/scripts pearcmd.php
Log:
since nobody has taken any action, fix Console_Getopt to be BC, and update the PEAR core to take
advantage of the new way. Use 1.2 to avoid any problems with versioning.
The core passes all unit tests with these changes, so they should work.
Andrei: feel free to change anything you don't like, this is just a make it work fix.
Index: php-src/pear/Console/Getopt.php
diff -u php-src/pear/Console/Getopt.php:1.25 php-src/pear/Console/Getopt.php:1.26
--- php-src/pear/Console/Getopt.php:1.25 Fri Dec 5 17:02:48 2003
+++ php-src/pear/Console/Getopt.php Thu Dec 11 00:54:33 2003
@@ -16,7 +16,7 @@
// | Author: Andrei Zmievski <andrei@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Getopt.php,v 1.25 2003/12/05 22:02:48 andrei Exp $
+// $Id: Getopt.php,v 1.26 2003/12/11 05:54:33 cellog Exp $
require_once 'PEAR.php';
@@ -52,8 +52,12 @@
* Long and short options can be mixed.
*
* Most of the semantics of this function are based on GNU getopt_long().
+ *
+ * <b>WARNING</b>: this function does not maintain full compatibility with GNU
getopt_long().
+ * To have full compatibility, use {@link getopt2()}
*
- * @param array $args an array of command-line arguments
+ * @param array $args an array of command-line arguments. The first argument
+ * should be the filename (like $argv[0]), unless it begins with
-
* @param string $short_options specifies the list of allowed short options
* @param array $long_options specifies the list of allowed long options
*
@@ -72,15 +76,47 @@
if (empty($args)) {
return array(array(), array());
}
- $opts = array();
- $non_opts = array();
settype($args, 'array');
if ($long_options) {
sort($long_options);
}
+ if (isset($args[0]{0}) && $args[0]{0} != '-') {
+ array_shift($args);
+ }
+ return Console_Getopt::doGetopt($args, $short_options, $long_options);
+ }
+ /**
+ * This function expects $args to contain only options and values
+ * @see getopt()
+ */
+ function getopt2($args, $short_options, $long_options = null)
+ {
+ // in case you pass directly readPHPArgv() as the first arg
+ if (PEAR::isError($args)) {
+ return $args;
+ }
+ if (empty($args)) {
+ return array(array(), array());
+ }
+
+ settype($args, 'array');
+
+ if ($long_options) {
+ sort($long_options);
+ }
+ return Console_Getopt::doGetopt($args, $short_options, $long_options);
+ }
+
+ /**
+ * The meat of {@link getopt()} and {@link getopt2()}
+ */
+ function doGetopt($args, $short_options, $long_options = null)
+ {
+ $opts = array();
+ $non_opts = array();
reset($args);
while (list($i, $arg) = each($args)) {
Index: php-src/pear/System.php
diff -u php-src/pear/System.php:1.31 php-src/pear/System.php:1.32
--- php-src/pear/System.php:1.31 Sat Dec 6 17:07:49 2003
+++ php-src/pear/System.php Thu Dec 11 00:54:34 2003
@@ -16,7 +16,7 @@
// | Authors: Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
//
-// $Id: System.php,v 1.31 2003/12/06 22:07:49 cellog Exp $
+// $Id: System.php,v 1.32 2003/12/11 05:54:34 cellog Exp $
//
require_once 'PEAR.php';
@@ -48,7 +48,7 @@
*
* @package System
* @author Tomas V.V.Cox <cox@idecnet.com>
-* @version $Revision: 1.31 $
+* @version $Revision: 1.32 $
* @access public
* @see http://pear.php.net/manual/
*/
@@ -68,7 +68,7 @@
if (!is_array($argv) && $argv !== null) {
$argv = preg_split('/\s+/', $argv);
}
- return Console_Getopt::getopt($argv, $short_options);
+ return Console_Getopt::getopt2($argv, $short_options);
}
/**
Index: php-src/pear/package-Console_Getopt.xml
diff -u php-src/pear/package-Console_Getopt.xml:1.9 php-src/pear/package-Console_Getopt.xml:1.10
--- php-src/pear/package-Console_Getopt.xml:1.9 Sat Dec 6 17:17:22 2003
+++ php-src/pear/package-Console_Getopt.xml Thu Dec 11 00:54:34 2003
@@ -21,11 +21,18 @@
<name>Stig Bakken</name>
<email>stig@php.net</email>
</maintainer>
+ <maintainer>
+ <user>cellog</user>
+ <role>helper</role>
+ <name>Greg Beaver</name>
+ <email>cellog@php.net</email>
+ </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>Revert of erroneous POSIX compatibility fix in getopt().
+getopt2() must be used for POSIX compatibility (BC break).</notes>
<state>stable</state>
<filelist>
<dir name="Console">
Index: php-src/pear/package-PEAR.xml
diff -u php-src/pear/package-PEAR.xml:1.88 php-src/pear/package-PEAR.xml:1.89
--- php-src/pear/package-PEAR.xml:1.88 Sat Dec 6 16:44:59 2003
+++ php-src/pear/package-PEAR.xml Thu Dec 11 00:54:34 2003
@@ -123,7 +123,7 @@
<deps>
<dep type="php" rel="ge" version="4.1"/>
<dep type="pkg" rel="ge"
version="1.1">Archive_Tar</dep>
- <dep type="pkg" rel="ge"
version="2.0">Console_Getopt</dep>
+ <dep type="pkg" rel="ge"
version="1.2">Console_Getopt</dep>
<dep type="pkg" rel="ge"
version="1.0.4">XML_RPC</dep>
<dep type="ext" rel="has"
optional="yes">xmlrpc</dep>
<dep type="ext" rel="has">xml</dep>
Index: php-src/pear/scripts/pearcmd.php
diff -u php-src/pear/scripts/pearcmd.php:1.4 php-src/pear/scripts/pearcmd.php:1.5
--- php-src/pear/scripts/pearcmd.php:1.4 Sat Dec 6 16:35:02 2003
+++ php-src/pear/scripts/pearcmd.php Thu Dec 11 00:54:35 2003
@@ -18,7 +18,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: pearcmd.php,v 1.4 2003/12/06 21:35:02 cellog Exp $
+// $Id: pearcmd.php,v 1.5 2003/12/11 05:54:35 cellog Exp $
ob_end_clean();
/**
@@ -49,7 +49,7 @@
$argv = Console_Getopt::readPHPArgv();
$progname = basename($argv[0]);
array_shift($argv);
-$options = Console_Getopt::getopt($argv, "c:C:d:D:Gh?sSqu:vV");
+$options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV");
if (PEAR::isError($options)) {
usage($options);
}
@@ -157,7 +157,7 @@
$short_args = $long_args = null;
PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
array_shift($options[1]);
- if (PEAR::isError($tmp = Console_Getopt::getopt($options[1], $short_args, $long_args))) {
+ if (PEAR::isError($tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args))) {
break;
}
list($tmpopt, $params) = $tmp;