diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 5f777c0..8d18454 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -32,6 +32,23 @@ describe("tests related to help message generation", function() }, "\r\n"), parser:prepare():get_help()) 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() local parser = Parser "foo" parser:argument "first" diff --git a/src/argparse.lua b/src/argparse.lua index dffc6bf..f6da4d7 100644 --- a/src/argparse.lua +++ b/src/argparse.lua @@ -51,7 +51,7 @@ local Parser = class { _require_command = true, _add_help = true, _fields = { - "name", "description", "require_command", + "name", "description", "epilog", "require_command", "action", "usage", "help", "add_help" } }:include(Declarative) @@ -60,9 +60,9 @@ local Command = Parser:extends { __name = "Command", _aliases = {}, _fields = { - "name", "aliases", "description", "target", - "require_command", "action", "usage", "help", - "add_help" + "name", "aliases", "description", "epilog", + "target", "require_command", "action", "usage", + "help", "add_help" } } @@ -435,6 +435,10 @@ function Parser:get_help() table.insert(blocks, table.concat(buf, "\r\n")) end + if self._epilog then + table.insert(blocks, self._epilog) + end + self._help = table.concat(blocks, "\r\n\r\n") end