From 30f6668c7d784020e71b6add98c2b85d2317fe51 Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Thu, 11 Dec 2003 19:28:25 +0000 Subject: [PATCH] Implement getopt2() method and keep BC for getopt(). --- pear/Console/Getopt.php | 28 +++++++++++++++++ pear/package-Console_Getopt.xml | 55 ++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/pear/Console/Getopt.php b/pear/Console/Getopt.php index 133a5bf313..52b2dea049 100644 --- a/pear/Console/Getopt.php +++ b/pear/Console/Getopt.php @@ -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)) { diff --git a/pear/package-Console_Getopt.xml b/pear/package-Console_Getopt.xml index 73738173c2..fa3275c2f3 100644 --- a/pear/package-Console_Getopt.xml +++ b/pear/package-Console_Getopt.xml @@ -23,9 +23,9 @@ short and long options. - 2.0 - 2003-12-06 - Revert of erroneous POSIX compatibility fix (BC break) + 1.2 + 2003-12-11 + Fix to preserve BC with 1.0 and allow correct behaviour for new users stable @@ -35,29 +35,40 @@ short and long options. - 0.11 - 2002-05-26 - POSIX getopt compatibility fix: treat first element of args - array as command name - - beta + 1.0 + 2002-09-13 + Stable release + stable - - 0.10 - 2002-05-12 - Packaging fix - beta - - - 0.9 - 2002-05-12 - Initial release - beta - + + 0.11 + 2002-05-26 + POSIX getopt compatibility fix: treat first element of args + array as command name + + beta + + + + + + + + 0.10 + 2002-05-12 + Packaging fix + beta + + + 0.9 + 2002-05-12 + Initial release + beta + - + -- 2.40.0