summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass2020-11-09 16:50:24 +0100
committerNathan Gass2020-11-09 16:52:06 +0100
commitea0289885c1fc4a8621d3a68893d3c08a2716504 (patch)
tree0134693fe40a96976f90fdff1bfc4662544cefe0
parent572e1c052267cd34cbedfcb7d51cda35a55667c1 (diff)
downloaditools-ea0289885c1fc4a8621d3a68893d3c08a2716504.tar.gz
itools-ea0289885c1fc4a8621d3a68893d3c08a2716504.tar.bz2
itools-ea0289885c1fc4a8621d3a68893d3c08a2716504.zip
no longer ignore extra positional arguments
-rw-r--r--it.class4
-rwxr-xr-xtest/getopt.t13
2 files changed, 7 insertions, 10 deletions
diff --git a/it.class b/it.class
index 74c9b7c..744c718 100644
--- a/it.class
+++ b/it.class
@@ -931,9 +931,7 @@ static function getopt($usage, $p = array())
$noopts = true;
}
- if (!$optionalargs && $result['args'])
- it::error("Optional arguments passed to script without optional args in usage"); # FIXME 2020-10 NG merge with normal usage errors below
- if ($err || $eat || $result['h'] || $result['help'] || $mandatoryargs)
+ if ($err || $eat || $result['h'] || $result['help'] || $mandatoryargs || (!$optionalargs && $result['args']))
{
if (is_resource($out = $result['h'] || $result['help'] ? STDOUT : STDERR))
fputs($out, trim($usage) . "\n");
diff --git a/test/getopt.t b/test/getopt.t
index aa2de52..48f7d9d 100755
--- a/test/getopt.t
+++ b/test/getopt.t
@@ -38,10 +38,9 @@ getopt_ok([], false, "Missing positional argument fails");
getopt_ok(['posarg', '--argument'], false, "Missing long named argument fails");
getopt_ok(['posarg', '-a'], false, "Missing short named argument fails");
-// FIXME 2020-10 NG enable after fixme in it.class
-// $GLOBALS['usage'] = it::replace('\s*\[VARARGS\]' => '', $GLOBALS['usage']);
-// getopt_ok(['posargs', 'vararg'], false, "Extra positional argument fails");
-// getopt_ok(['posargs', '--zero', 'vararg'], false, "Extra positional argument fails after long argument");
-// getopt_ok(['posargs', '-0', 'vararg'], false, "Extra positional argument fails after short argument");
-// getopt_ok(['posargs', '--argument', 'value', 'vararg'], false, "Extra positional argument fails after long argument with value");
-// getopt_ok(['posargs', '-a', 'value', 'vararg'], false, "Extra positional argument fails after short argument with value");
+$GLOBALS['usage'] = it::replace(['\s*\[VARARGS\]' => ''], $GLOBALS['usage']);
+getopt_ok(['posargs', 'vararg'], false, "Extra positional argument fails");
+getopt_ok(['posargs', '--zero', 'vararg'], false, "Extra positional argument fails after long argument");
+getopt_ok(['posargs', '-0', 'vararg'], false, "Extra positional argument fails after short argument");
+getopt_ok(['posargs', '--argument', 'value', 'vararg'], false, "Extra positional argument fails after long argument with value");
+getopt_ok(['posargs', '-a', 'value', 'vararg'], false, "Extra positional argument fails after short argument with value");