mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Mark entire option as optional if there is default value
This commit is contained in:
@@ -43,13 +43,16 @@ describe("tests related to usage message generation", function()
|
||||
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"
|
||||
parser:argument "input"
|
||||
:default "a.in"
|
||||
parser:option "-f" "--from"
|
||||
:default "there"
|
||||
parser:option "-o" "--output"
|
||||
:default "a.out"
|
||||
:count(1)
|
||||
|
||||
assert.equal(
|
||||
[=[Usage: foo [--from [<from>]] [<output>]]=],
|
||||
[=[Usage: foo [-f [<from>]] [-o [<output>]] [<input>]]=],
|
||||
parser:prepare():get_usage()
|
||||
)
|
||||
end)
|
||||
|
@@ -212,7 +212,7 @@ function Option:get_usage()
|
||||
table.insert(self._usage, 1, self._name)
|
||||
self._usage = table.concat(self._usage, " ")
|
||||
|
||||
if self._mincount == 0 then
|
||||
if self._mincount == 0 or self._default then
|
||||
self._usage = "[" .. self._usage .. "]"
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user