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()
|
it("creates correct usage message for elements with default value", function()
|
||||||
local parser = Parser "foo"
|
local parser = Parser "foo"
|
||||||
:add_help(false)
|
:add_help(false)
|
||||||
parser:argument "output"
|
parser:argument "input"
|
||||||
:default "a.out"
|
:default "a.in"
|
||||||
parser:option "--from" "-f"
|
parser:option "-f" "--from"
|
||||||
:default "there"
|
:default "there"
|
||||||
|
parser:option "-o" "--output"
|
||||||
|
:default "a.out"
|
||||||
|
:count(1)
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
[=[Usage: foo [--from [<from>]] [<output>]]=],
|
[=[Usage: foo [-f [<from>]] [-o [<output>]] [<input>]]=],
|
||||||
parser:prepare():get_usage()
|
parser:prepare():get_usage()
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
@@ -212,7 +212,7 @@ function Option:get_usage()
|
|||||||
table.insert(self._usage, 1, self._name)
|
table.insert(self._usage, 1, self._name)
|
||||||
self._usage = table.concat(self._usage, " ")
|
self._usage = table.concat(self._usage, " ")
|
||||||
|
|
||||||
if self._mincount == 0 then
|
if self._mincount == 0 or self._default then
|
||||||
self._usage = "[" .. self._usage .. "]"
|
self._usage = "[" .. self._usage .. "]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user