Change error messages for missing elements

* For arguments: "argument 'foo' is required" -> "missing argument 'foo'"
* For options: "option '--foo' must be used at least 1 time" ->
  "missing option '--foo'"
This commit is contained in:
mpeterv
2015-10-30 15:13:30 +03:00
parent 93522f1856
commit babe715548
5 changed files with 12 additions and 9 deletions

View File

@@ -97,7 +97,7 @@ describe("tests related to positional arguments", function()
local parser = Parser()
parser:argument "foo"
assert.has_error(function() parser:parse{} end, "argument 'foo' is required")
assert.has_error(function() parser:parse{} end, "missing argument 'foo'")
end)
it("handles extra arguments with several arguments correctly", function()
@@ -113,7 +113,7 @@ describe("tests related to positional arguments", function()
parser:argument "foo1"
parser:argument "foo2"
assert.has_error(function() parser:parse{"bar"} end, "argument 'foo2' is required")
assert.has_error(function() parser:parse{"bar"} end, "missing argument 'foo2'")
end)
it("handles too few arguments with multi-argument correctly", function()
@@ -121,7 +121,7 @@ describe("tests related to positional arguments", function()
parser:argument "foo" {
args = "+"
}
assert.has_error(function() parser:parse{} end, "argument 'foo' is required")
assert.has_error(function() parser:parse{} end, "missing argument 'foo'")
end)
it("handles too many arguments with multi-argument correctly", function()
@@ -159,7 +159,7 @@ describe("tests related to positional arguments", function()
parser:argument "foo2" {
args = "*"
}
assert.has_error(function() parser:parse{} end, "argument 'foo1' is required")
assert.has_error(function() parser:parse{} end, "missing argument 'foo1'")
end)
end)
end)

View File

@@ -20,7 +20,7 @@ describe("tests related to CLI behaviour #unsafe", function()
assert.equal([[
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
Error: argument 'input' is required
Error: missing argument 'input'
]], get_output(""))
end)
@@ -62,7 +62,7 @@ Did you mean 'install'?
assert.equal([[
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
Error: argument 'rock' is required
Error: missing argument 'rock'
]], get_output("foo install"))
end)

View File

@@ -298,7 +298,8 @@ describe("tests related to options", function()
parser:option "-f" "--foo" {
count = "3-4"
}
assert.has_error(function() parser:parse{"-fFOO", "-fBAR"} end, "option '-f' must be used at least 3 times")
assert.has_error(function() parser:parse{"-fFOO", "--foo=BAR"} end, "option '--foo' must be used at least 3 times")
assert.has_error(function() parser:parse{} end, "missing option '-f'")
end)
end)
end)

View File

@@ -15,7 +15,7 @@ describe("tests related to :pparse()", function()
parser:argument "foo"
local ok, errmsg = parser:pparse{}
assert.is_false(ok)
assert.equal("argument 'foo' is required", errmsg)
assert.equal("missing argument 'foo'", errmsg)
end)
it("rethrows errors from callbacks", function()

View File

@@ -809,7 +809,7 @@ function ElementState:close()
else
if #self.args == 0 then
if getmetatable(self.element) == Argument then
self:error("%s is required", self.name)
self:error("missing %s", self.name)
elseif self.element._maxargs == 1 then
self:error("%s requires an argument", self.name)
end
@@ -996,6 +996,8 @@ function ParseState:finalize()
option:invoke(name)
option:close()
end
elseif option.invocations == 0 then
self:error("missing %s", name)
else
self:error("%s must be used %s", name, bound("time", mincount, option.element._maxcount))
end