mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
In usage message, mark arguments as optional if there is a default value
This commit is contained in:
@@ -40,6 +40,20 @@ describe("tests related to usage message generation", function()
|
||||
)
|
||||
end)
|
||||
|
||||
it("creates correct usage message for elements with default value", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
parser:argument "output"
|
||||
:default "a.out"
|
||||
parser:option "--from" "-f"
|
||||
:default "there"
|
||||
|
||||
assert.equal(
|
||||
[=[Usage: foo [--from [<from>]] [<output>]]=],
|
||||
parser:prepare():get_usage()
|
||||
)
|
||||
end)
|
||||
|
||||
it("creates correct usage message for commands", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
|
@@ -98,10 +98,16 @@ local Flag = Option:extends {
|
||||
function Argument:get_arg_usage(argname)
|
||||
argname = self._argname or argname
|
||||
local buf = {}
|
||||
local required_argname = argname
|
||||
|
||||
if self._default then
|
||||
required_argname = "[" .. argname .. "]"
|
||||
end
|
||||
|
||||
local i = 1
|
||||
|
||||
while i <= math.min(self._minargs, 3) do
|
||||
table.insert(buf, argname)
|
||||
table.insert(buf, required_argname)
|
||||
i = i+1
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user