more tests, fixed wrong behaviour of joined options

This commit is contained in:
mpeterv
2014-01-01 14:49:31 +04:00
parent ebd1c7b268
commit 582bdc1738
3 changed files with 83 additions and 10 deletions

View File

@@ -250,7 +250,7 @@ function Parser:parse(args)
element = self:assert(state.context[name], "unknown option " .. name)
state:handle_option(name)
if i ~= #data and not (element.minargs == 0 and data:sub(i+1, i+1):match "[a-zA-Z]") then
if i ~= #data and not (element.minargs == 0 and state.context["-" .. data:sub(i+1, i+1)]) then
state:handle_argument(data:sub(i+1))
break
end

View File

@@ -98,7 +98,7 @@ function State:_check()
if #invocations > element.maxcount then
if element.no_overwrite then
self:_error("option %s can only be used %d times", element.name, element.maxcount)
self:_error("option %s must be used at most %d times", element.name, element.maxcount)
else
local new_invocations = {}
for i = 1, element.maxcount do
@@ -111,13 +111,8 @@ function State:_check()
self:_assert(#invocations >= element.mincount, "option %s must be used at least %d times", element.name, element.mincount)
for _, passed in ipairs(invocations) do
if element.type == "option" then
self:_assert(#passed <= element.maxargs, "%s takes at most %d arguments", element.name, element.maxargs)
self:_assert(#passed >= element.minargs, "%s takes at least %d arguments", element.name, element.minargs)
else
self:_assert(#passed <= element.maxargs, "too many arguments")
self:_assert(#passed >= element.minargs, "too few arguments")
end
self:_assert(#passed <= element.maxargs, "too many arguments")
self:_assert(#passed >= element.minargs, "too few arguments")
end
self._result[element.target] = invocations