Improved error message

Report '1 times' as '1 time'
This commit is contained in:
mpeterv
2014-02-23 16:58:27 +04:00
parent 5c82cb4c2e
commit aeacbeb589
2 changed files with 11 additions and 3 deletions

View File

@@ -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