mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-30 03:52:19 +00:00
more tests, fixed wrong behaviour of joined options
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user