summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Helbling2011-12-08 13:22:21 +0000
committerChristian Helbling2011-12-08 13:22:21 +0000
commite79ea1263b41976cb53ebba155f6d0b541e69602 (patch)
tree966d9f131e7c5953219b72d3e65f6c9724dcf1e9
parent9464c15f54a175ea907baeea1287e20d262b9224 (diff)
downloaditools-e79ea1263b41976cb53ebba155f6d0b541e69602.tar.gz
itools-e79ea1263b41976cb53ebba155f6d0b541e69602.tar.bz2
itools-e79ea1263b41976cb53ebba155f6d0b541e69602.zip
allow -0 as shortarg in getopt
-rw-r--r--it.class4
-rwxr-xr-xtests/getopt.t6
2 files changed, 8 insertions, 2 deletions
diff --git a/it.class b/it.class
index d28423d..1eafcea 100644
--- a/it.class
+++ b/it.class
@@ -612,7 +612,7 @@ static function getopt($helplines)
if ($longoptname || $shortoptname)
{
- if ($longoptname && $shortoptname)
+ if ($longoptname && ($shortoptname || $shortoptname === "0"))
$alias[$shortoptname] = $longoptname;
$witharg[$longoptname ? $longoptname : $shortoptname] = $longoptarg || $shortoptarg;
@@ -643,7 +643,7 @@ static function getopt($helplines)
else
$result[$optname] = $val ? substr($val, 1) : true;
}
- else if ($letters = it::match('^-(\w+)', $arg))
+ else if (($letters = it::match('^-(\w+)', $arg)) || $letters === "0")
{
foreach (explode("\n", trim(chunk_split($letters, 1, "\n"))) as $letter)
{
diff --git a/tests/getopt.t b/tests/getopt.t
index 56974fe..7a84588 100755
--- a/tests/getopt.t
+++ b/tests/getopt.t
@@ -7,6 +7,7 @@ $GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS]
Some help to a not existing program
-h,--help the help argument
-a,--argument=ARG the arg argument
+ -0,--zero testworthy shortarg
";
function getopt_ok($argv, $exp, $name)
@@ -21,3 +22,8 @@ foreach (array("" => "blah gnaber", " (umlaute)" => "pre üäpost") as $variant =>
getopt_ok(array('--argument', $testarg), $testarg, "Long version with space" . $variant);
getopt_ok(array("--argument=$testarg"), $testarg, "Long version with equal" . $variant);
}
+
+$_SERVER['argv'] = array('doesnotexist.php', '-0');
+$zero_opts = it::getopt($GLOBALS['usage']);
+ok($zero_opts['zero'], '-0');
+