mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Improved error message
Report '1 times' as '1 time'
This commit is contained in:
@@ -243,7 +243,7 @@ describe("tests related to options", function()
|
||||
count = 1,
|
||||
overwrite = false
|
||||
})
|
||||
assert.has_error(function() parser:parse{"-qq"} end, "option '-q' must be used at most 1 times")
|
||||
assert.has_error(function() parser:parse{"-qq"} end, "option '-q' must be used at most 1 time")
|
||||
end)
|
||||
|
||||
it("handles too few invocations correctly", function()
|
||||
|
@@ -493,6 +493,14 @@ local function get_tip(context, wrong_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function plural(x)
|
||||
if x == 1 then
|
||||
return ""
|
||||
end
|
||||
|
||||
return "s"
|
||||
end
|
||||
|
||||
function Parser:_parse(args, errhandler)
|
||||
args = args or arg
|
||||
self._name = self._name or args[0]
|
||||
@@ -546,7 +554,7 @@ function Parser:_parse(args, errhandler)
|
||||
if element._overwrite then
|
||||
overwrite = true
|
||||
else
|
||||
error_("option '%s' must be used at most %d times", element._name, element._maxcount)
|
||||
error_("option '%s' must be used at most %d time%s", element._name, element._maxcount, plural(element._maxcount))
|
||||
end
|
||||
else
|
||||
invocations[element] = invocations[element]+1
|
||||
@@ -772,7 +780,7 @@ function Parser:_parse(args, errhandler)
|
||||
close(option)
|
||||
end
|
||||
else
|
||||
error_("option '%s' must be used at least %d times", option._name, option._mincount)
|
||||
error_("option '%s' must be used at least %d time%s", option._name, option._mincount, plural(option._mincount))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user