Added epilog field

This commit is contained in:
mpeterv
2014-02-23 16:44:13 +04:00
parent 7994dded7e
commit 5c82cb4c2e
2 changed files with 25 additions and 4 deletions

View File

@@ -32,6 +32,23 @@ describe("tests related to help message generation", function()
}, "\r\n"), parser:prepare():get_help()) }, "\r\n"), parser:prepare():get_help())
end) end)
it("uses description and epilog", function()
local parser = Parser "foo"
:description "A description. "
:epilog "An epilog. "
assert.equal(table.concat({
"Usage: foo [-h]",
"",
"A description. ",
"",
"Options: ",
" -h, --help Show this help message and exit. ",
"",
"An epilog. "
}, "\r\n"), parser:prepare():get_help())
end)
it("creates correct help message for arguments", function() it("creates correct help message for arguments", function()
local parser = Parser "foo" local parser = Parser "foo"
parser:argument "first" parser:argument "first"

View File

@@ -51,7 +51,7 @@ local Parser = class {
_require_command = true, _require_command = true,
_add_help = true, _add_help = true,
_fields = { _fields = {
"name", "description", "require_command", "name", "description", "epilog", "require_command",
"action", "usage", "help", "add_help" "action", "usage", "help", "add_help"
} }
}:include(Declarative) }:include(Declarative)
@@ -60,9 +60,9 @@ local Command = Parser:extends {
__name = "Command", __name = "Command",
_aliases = {}, _aliases = {},
_fields = { _fields = {
"name", "aliases", "description", "target", "name", "aliases", "description", "epilog",
"require_command", "action", "usage", "help", "target", "require_command", "action", "usage",
"add_help" "help", "add_help"
} }
} }
@@ -435,6 +435,10 @@ function Parser:get_help()
table.insert(blocks, table.concat(buf, "\r\n")) table.insert(blocks, table.concat(buf, "\r\n"))
end end
if self._epilog then
table.insert(blocks, self._epilog)
end
self._help = table.concat(blocks, "\r\n\r\n") self._help = table.concat(blocks, "\r\n\r\n")
end end