mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Add argument choices
This commit is contained in:
@@ -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'
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
-----------------------------
|
||||
|
||||
|
Reference in New Issue
Block a user