mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Autowrap parser description and epilog, too
This commit is contained in:
@@ -593,5 +593,30 @@ Options:
|
||||
--foo <foo> words, it should be broken down.
|
||||
-h, --help Show this help message and exit.]], parser:get_help())
|
||||
end)
|
||||
|
||||
it("autowraps description and epilog", function()
|
||||
local parser = Parser "foo"
|
||||
:help_max_width(80)
|
||||
:description("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " ..
|
||||
"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation " ..
|
||||
"ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
||||
:epilog("Duis aute irure dolor in reprehenderit " ..
|
||||
"in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat " ..
|
||||
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
|
||||
|
||||
assert.equal([[
|
||||
Usage: foo [-h]
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message and exit.
|
||||
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
|
||||
culpa qui officia deserunt mollit anim id est laborum.]], parser:get_help())
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
@@ -955,8 +955,16 @@ function Parser:get_help()
|
||||
|
||||
local blocks = {self:get_usage()}
|
||||
|
||||
local help_max_width = self:_inherit_property("help_max_width")
|
||||
|
||||
if self._description then
|
||||
table.insert(blocks, self._description)
|
||||
local description = self._description
|
||||
|
||||
if help_max_width then
|
||||
description = table.concat(autowrap(split_lines(description), help_max_width), "\n")
|
||||
end
|
||||
|
||||
table.insert(blocks, description)
|
||||
end
|
||||
|
||||
-- 1. Put groups containing arguments first, then other arguments.
|
||||
@@ -1005,7 +1013,13 @@ function Parser:get_help()
|
||||
end
|
||||
|
||||
if self._epilog then
|
||||
table.insert(blocks, self._epilog)
|
||||
local epilog = self._epilog
|
||||
|
||||
if help_max_width then
|
||||
epilog = table.concat(autowrap(split_lines(epilog), help_max_width), "\n")
|
||||
end
|
||||
|
||||
table.insert(blocks, epilog)
|
||||
end
|
||||
|
||||
return table.concat(blocks, "\n\n")
|
||||
|
Reference in New Issue
Block a user