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