getopts : manage correctely the help and the tests

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3528 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-04-24 12:59:27 +00:00
parent 064407ff1c
commit 626e4d66f6

View File

@@ -88,7 +88,7 @@ class getopts
else
$long = array ();
}
if ($short[0] === ":")
if (substr ($short, 0, 1) !== false && $short[0] === ":")
throw new \Exception ("Short option can't start by semi-colon", 500);
if ((strpos ($short, ":") !== false ||
strpos (implode ($long), ":") !== false) &&
@@ -248,9 +248,10 @@ class getopts
$token = "$prevToken$token";
$prevToken = "";
}
if ($this->restOfLine !== null)
$this->restOfLine[] = $token;
elseif (trim ($token) !== "")
//if ($this->restOfLine !== null)
// $this->restOfLine[] = $token;
//elseif (trim ($token) !== "")
if (trim ($token) !== "")
$tokens[] = $token;
$offset = $end + 1;
}
@@ -258,7 +259,7 @@ class getopts
// Analyze the tokens to fill the $this->parameters
if ($this->restOfLine === null)
$this->restOfLine = "";
$this->restOfLine = array ();
if (! array_key_exists (0, $tokens))
throw new \Exception ("Can not find the program name (\$argv[0]", 500);
$this->programName = array_shift ($tokens);
@@ -482,7 +483,7 @@ class getopts
$paramOptional = false;
if ($i > 0)
$d .= ", ";
$d .= $option;
$d .= str_replace (":", "", $option);
if ($param)
{
$d .= " ";