Add summary command property

This commit is contained in:
Paul Ouellette
2019-06-13 18:32:41 -04:00
parent e30288c54a
commit b717d7b11c
3 changed files with 43 additions and 1 deletions

View File

@@ -140,3 +140,43 @@ This can be changed using ``require_command`` property.
local parser = argparse() local parser = argparse()
:require_command(false) :require_command(false)
parser:command "install" parser:command "install"
Command summaries
-----------------
The description for commands shown in the parent parser help message can be set
with the ``summary`` property.
.. code-block:: lua
:linenos:
parser:command "install"
:summary "Install a rock."
:description "A long description for the install command."
.. code-block:: none
$ lua script.lua --help
.. code-block:: none
Usage: script.lua [-h] <command> ...
Options:
-h, --help Show this help message and exit.
Commands:
install Install a rock.
.. code-block:: none
$ lua script.lua install --help
.. code-block:: none
Usage: script.lua install [-h]
A long description for the install command.
Options:
-h, --help Show this help message and exit.

View File

@@ -201,6 +201,7 @@ Other properties:
=========================== ========================== =========================== ==========================
Property Type Property Type
=========================== ========================== =========================== ==========================
``summary`` String
``target`` String ``target`` String
``usage`` String ``usage`` String
``help`` String ``help`` String

View File

@@ -306,6 +306,7 @@ local Command = class({
multiname, multiname,
typechecked("description", "string"), typechecked("description", "string"),
typechecked("epilog", "string"), typechecked("epilog", "string"),
typechecked("summary", "string"),
typechecked("target", "string"), typechecked("target", "string"),
typechecked("usage", "string"), typechecked("usage", "string"),
typechecked("help", "string"), typechecked("help", "string"),
@@ -589,7 +590,7 @@ function Argument:_get_description()
end end
function Command:_get_description() function Command:_get_description()
return self._description or "" return self._summary or self._description or ""
end end
function Option:_get_usage() function Option:_get_usage()