cvs: php4 /pear/Console Getopt.php /pear/Console/tests 001-getopt.phpt
| From: | Stig Bakken | Date: | Sun, 12 May 2002 07:13:49 +0000 |
| Subject: | cvs: php4 /pear/Console Getopt.php /pear/Console/tests 001-getopt.phpt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3769@lists.php.net to get a copy of this message | ||
ssb Sun May 12 03:13:49 2002 EDT
Added files:
/php4/pear/Console/tests 001-getopt.phpt
Modified files:
/php4/pear/Console Getopt.php
Log:
* Try again: fixed Console_Getopt::getopt so it does not steal options
after the first non-option argument. Added test.
Index: php4/pear/Console/Getopt.php
diff -u php4/pear/Console/Getopt.php:1.12 php4/pear/Console/Getopt.php:1.13
--- php4/pear/Console/Getopt.php:1.12 Sat May 11 12:39:39 2002
+++ php4/pear/Console/Getopt.php Sun May 12 03:13:48 2002
@@ -16,7 +16,7 @@
// | Author: Andrei Zmievski <andrei@ispi.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Getopt.php,v 1.12 2002/05/11 16:39:39 ssb Exp $
+// $Id: Getopt.php,v 1.13 2002/05/12 07:13:48 ssb Exp $
require_once 'PEAR.php';
@@ -89,9 +89,8 @@
}
if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} ==
'-' && !$long_options)) {
- $non_opts[] = $arg;
- //$non_opts = array_merge($non_opts, array_slice($args, $i));
- //break;
+ $non_opts = array_merge($non_opts, array_slice($args, $i));
+ break;
} elseif (strlen($arg) > 1 && $arg{1} == '-') {
$error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts,
$args);
if (PEAR::isError($error))
Index: php4/pear/Console/tests/001-getopt.phpt
+++ php4/pear/Console/tests/001-getopt.phpt
--TEST--
Console_Getopt
--FILE--
<?php
error_reporting(E_ALL);
chdir(dirname(__FILE__));
include "../Getopt.php";
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s\n\n");
function test($argstr, $optstr) {
$argv = split('[[:space:]]+', $argstr);
if (PEAR::isError($options = Console_Getopt::getopt($argv, $optstr))) {
return;
}
$opts = $options[0];
$non_opts = $options[1];
$i = 0;
print "options: ";
foreach ($opts as $o => $d) {
if ($i++ > 0) {
print ", ";
}
print $d[0] . '=' . $d[1];
}
print "\n";
print "params: " . implode(", ", $non_opts) . "\n";
print "\n";
}
test("-abc", "abc");
test("-abc foo", "abc");
test("-abc foo", "abc:");
test("-abc foo bar gazonk", "abc");
test("-abc foo bar gazonk", "abc:");
test("-a -b -c", "abc");
test("-a -b -c", "abc:");
test("-abc", "ab:c");
test("-abc foo -bar gazonk", "abc");
?>
--EXPECT--
options: a=, b=, c=
params:
options: a=, b=, c=
params: foo
options: a=, b=, c=foo
params:
options: a=, b=, c=
params: foo, bar, gazonk
options: a=, b=, c=foo
params: bar, gazonk
options: a=, b=, c=
params:
Console_Getopt: option requires an argument -- c
options: a=, b=c
params:
options: a=, b=, c=
params: foo, -bar, gazonk