From 626e4d66f6c3fc73defd6a97523ec1b5be26fd02 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 24 Apr 2017 12:59:27 +0000 Subject: [PATCH] getopts : manage correctely the help and the tests git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3528 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- getopts.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/getopts.php b/getopts.php index a3aa344..18cd6df 100644 --- a/getopts.php +++ b/getopts.php @@ -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 .= " ";