cvs: pear /Console_Getargs Getargs.php
| From: | Scott Mattocks | Date: | Mon, 08 Nov 2004 18:48:41 +0000 |
| Subject: | cvs: pear /Console_Getargs Getargs.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-25783@lists.php.net to get a copy of this message | ||
scottmattocks Mon Nov 8 13:48:41 2004 EDT
Modified files:
/pear/Console_Getargs Getargs.php
Log:
Fix for bug #2599: parameters and using "--".
http://cvs.php.net/diff.php/pear/Console_Getargs/Getargs.php?r1=1.12&r2=1.13&ty=u
Index: pear/Console_Getargs/Getargs.php
diff -u pear/Console_Getargs/Getargs.php:1.12 pear/Console_Getargs/Getargs.php:1.13
--- pear/Console_Getargs/Getargs.php:1.12 Mon Nov 1 16:39:39 2004
+++ pear/Console_Getargs/Getargs.php Mon Nov 8 13:48:41 2004
@@ -16,7 +16,7 @@
// | Author: Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Getargs.php,v 1.12 2004/11/01 21:39:39 scottmattocks Exp $
+// $Id: Getargs.php,v 1.13 2004/11/08 18:48:41 scottmattocks Exp $
require_once 'PEAR.php';
@@ -622,16 +622,15 @@
// Go through the options and parse the arguments for each.
for ($i = 0, $count = count($this->args); $i < $count; $i++) {
$arg = $this->args[$i];
-
- if ($arg === '--') {
- // '--' alone breaks the loop
- continue;
- }
if ($arg === '--help' || $arg === '-h') {
// Asking for help breaks the loop.
return PEAR::raiseError(null, CONSOLE_GETARGS_HELP, PEAR_ERROR_RETURN);
+
}
- if (strlen($arg) > 1 && $arg{0} == '-' && $arg{1} ==
'-') {
+ if ($arg === '--') {
+ // '--' alone signals the start of "parameters"
+ $err = $this->parseArg(CONSOLE_GETARGS_PARAMS, true, ++$i);
+ } elseif (strlen($arg) > 1 && $arg{0} == '-' && $arg{1} ==
'-') {
// Long name used (--option)
$err = $this->parseArg(substr($arg, 2), true, $i);
} else if (strlen($arg) > 1 && $arg{0} == '-') {
@@ -712,6 +711,11 @@
break;
}
}
+
+ // If no option name is found, assume -- was passed.
+ if ($opt == '') {
+ $long = CONSOLE_GETARGS_PARAMS;
+ }
if (isset($long)) {
// A match was found.
@@ -851,28 +855,30 @@
$pos = max($pos - 1, -1);
}
for ($i = $pos + 1; $i <= count($this->args); $i++) {
- if (isset($this->args[$i]) && $this->isValue($this->args[$i])) {
+ $paramFull = $max <= count($this->getValue($optname)) && $max != -1;
+ if (isset($this->args[$i]) && $this->isValue($this->args[$i])
&& !$paramFull) {
// Add the argument value until the next option is hit.
$this->updateValue($optname, $this->args[$i]);
$added++;
$pos++;
// Only keep trying if we haven't filled up yet.
// or there is no limit
- if ($added < $max || $max < 0) {
+ if (($added < $max || $max < 0) && ($max < 0 || !$paramFull)) {
continue;
}
}
- if ($min > $added) {
+ if ($min > $added && !$paramFull) {
// There aren't enough arguments for this option.
+ echo $max . "\t" . count ($this->getValue($optname)) . "\t"
. $optname . "\n";
return PEAR::raiseError('Argument '.$optname.' expects at least
'.$min.(($min > 1) ? ' values' : ' value'),
CONSOLE_GETARGS_ERROR_USER, PEAR_ERROR_RETURN,
null, 'Console_Getargs_Options::setValue()');
- } elseif ($max !== -1 && $added > $max) {
+ } elseif ($max !== -1 && $paramFull) {
// Too many arguments for this option.
// Try to add the extra options to parameters.
if (isset($this->_config[CONSOLE_GETARGS_PARAMS]) && $optname !=
CONSOLE_GETARGS_PARAMS) {
return $this->setValue(CONSOLE_GETARGS_PARAMS, '', ++$pos);
- } elseif ($optname == CONSOLE_GETARGS_PARAMS && !isset($this->args[$i +
1])) {
+ } elseif ($optname == CONSOLE_GETARGS_PARAMS && empty($this->args[$i]))
{
$pos += $added;
break;
} else {