mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Rework usage message building and support arguments in mutexes
Ref #11.
This commit is contained in:
@@ -19,6 +19,24 @@ describe("tests related to mutexes", function()
|
||||
assert.same({}, args)
|
||||
end)
|
||||
|
||||
it("handles mutex with an argument", function()
|
||||
local parser = Parser()
|
||||
parser:mutex(
|
||||
parser:flag "-q" "--quiet"
|
||||
:description "Supress output.",
|
||||
parser:argument "log"
|
||||
:args "?"
|
||||
:description "Log file"
|
||||
)
|
||||
|
||||
local args = parser:parse{"-q"}
|
||||
assert.same({quiet = true}, args)
|
||||
args = parser:parse{"log.txt"}
|
||||
assert.same({log = "log.txt"}, args)
|
||||
args = parser:parse{}
|
||||
assert.same({}, args)
|
||||
end)
|
||||
|
||||
it("handles mutex with default value", function()
|
||||
local parser = Parser()
|
||||
parser:mutex(
|
||||
@@ -48,6 +66,24 @@ describe("tests related to mutexes", function()
|
||||
end, "option '--quiet' can not be used together with option '-v'")
|
||||
end)
|
||||
|
||||
it("raises an error if mutex with an argument is broken", function()
|
||||
local parser = Parser()
|
||||
parser:mutex(
|
||||
parser:flag "-q" "--quiet"
|
||||
:description "Supress output.",
|
||||
parser:argument "log"
|
||||
:args "?"
|
||||
:description "Log file"
|
||||
)
|
||||
|
||||
assert.has_error(function()
|
||||
parser:parse{"-q", "log.txt"}
|
||||
end, "argument 'log' can not be used together with option '-q'")
|
||||
assert.has_error(function()
|
||||
parser:parse{"log.txt", "--quiet"}
|
||||
end, "option '--quiet' can not be used together with argument 'log'")
|
||||
end)
|
||||
|
||||
it("handles multiple mutexes", function()
|
||||
local parser = Parser()
|
||||
parser:mutex(
|
||||
|
Reference in New Issue
Block a user