Add argument choices

This commit is contained in:
Paul Ouellette
2019-05-27 17:54:05 -04:00
parent d08b637d54
commit dcd5162710
6 changed files with 64 additions and 0 deletions

View File

@@ -68,3 +68,24 @@ If more than one argument can be consumed, a table is used to store the data.
pair = {"foo", "bar"},
optional = "baz"
}
Setting argument choices
------------------------
The ``choices`` property can be used to restrict an argument to a set of choices. Its value is an array of string choices.
.. code-block:: lua
:linenos:
parser:argument "direction"
:choices {"north", "south", "east", "west"}
.. code-block:: none
$ lua script.lua foo
.. code-block:: none
Usage: script.lua [-h] <direction>
Error: argument 'direction' must be one of 'north', 'south', 'east', 'west'

View File

@@ -242,6 +242,7 @@ Property Type
``defmode`` String
``show_default`` Boolean
``argname`` String or table
``choices`` Table
``action`` Function or string
``init`` Any
``hidden`` Boolean
@@ -273,6 +274,7 @@ Property Type
``show_default`` Boolean
``overwrite`` Booleans
``argname`` String or table
``choices`` Table
``action`` Function or string
``init`` Any
``hidden`` Boolean

View File

@@ -107,6 +107,11 @@ Just as arguments, options can be configured to take several command line argume
Note that the data passed to ``optional`` option is stored in an array. That is necessary to distinguish whether the option was invoked without an argument or it was not invoked at all.
Setting argument choices
------------------------
The ``choices`` property can be used to specify a list of choices for an option argument in the same way as for arguments.
Setting number of invocations
-----------------------------