Module getopt
Argument parsing.
Provides an argument parser loosely inspired by GNU getopt; its interface is tailored to Lua rather than C, and it is thereby somewhat less obtuse. The code is taken from ULOS 1 and has been modified very slightly to work with ULOS 2.
Functions
getopt (_opts, _args) | Process program arguments according to the given options. |
build (supported) | Build a set of options and usage information. |
process (parameters) | Process options more easily. |
Tables
options | Options given to getopt |
Supported | Supported options given to build . |
Functions
- getopt (_opts, _args)
-
Process program arguments according to the given options.
Takes the given table of options, and processes the given arguments accordingly.
The returned table of options will vary slightly depending whether the
can_repeat_opts
option is set. If it is set, all values returned in theopts
table will be tables containing an array of all the values given to that option over one or more occurrences of that option (possibly just one item). Otherwise, the most recent occurrence of an option takes precedence and all values inopts
are strings. Keys in the returnedopts
table are always strings corresponding to the name of the option. Option names should never begin with a-
or--
.Parameters:
Returns:
- build (supported)
-
Build a set of options and usage information.
For some example usage, see getopt.build.lua.
Parameters:
Returns:
- process (parameters)
-
Process options more easily.
Effectively build and getopt combined.
For example usage, see getopt.process.lua.
Parameters:
- parameters
table
An amalgamation of the arguments given to build and getopt, with the addition of an
args
field to hold the raw arguments.
Returns:
- parameters
table
An amalgamation of the arguments given to build and getopt, with the addition of an
Tables
- options
-
Options given to getopt
Fields:
- options table Key-value pairs of all possible options, where the key is the option name and the value is a boolean indicating whether that option takes an argument. This is the only mandatory field.
- help_message string A help message that is written to the standard error stream when an error condition is reached.
- exit_on_bad_opt
boolean
Whether it is an error to find an invalid option (one not specified in the
options
table). - finish_after_arg boolean Whether to stop processing options after any non-option argument is reached.
- can_repeat_opts boolean Whether options may be repeated.
- exclude_numbers
boolean
Whether to exclude numbers from short options, e.g.
-700
- Supported
-
Supported options given to
build
.Fields: