Files changed (1)
+--[[ The function CmdLineOptions takes the command-line options and processes them according to a series of functions it is given. It can handle any options of the standard forms, such as:
+- A table of functions, where the key name matches the options. Note that the match will be case-sensitive.
+- A value to be passed to the functions. This allows them to be a bit more independent without having to use upvalue tricks.
+- A nullary iterator function to iterate over all of the options associated with the command. It can have 0 iterations. It is OK to iterate multiple times. The iterator returns two values: the parameter and the parameter's 1-base index.
+The return value from the processing function is the number of options processed. If `nil` is returned, then it is assumed that *all* available options were processed.
+The processor functions are called within a `pcall`, so any errors will be assumed to be processing errors related to that option. Appropriate error messages will be emitted mentioning the option name, so it doesn't need to keep its own name. It is up to each processor to decide if it has enough or too many parameters and error out if it does. Processing of command line options will error if there is a failure.
+The processor assumes that strings that begin with a `-` character is an option. If a parameter is specified with the `-option=param` syntax, then it is assumed to have exactly one parameter. Thus the next value is assumed to be an option. For all other option formats, the number of processed arguments is decided upon by the processing function. If it returns `nil`, then it assumes all arguments were processed.
+Any "options" that do not conform to option syntax are assumed to be positional arguments. They are stored in an array and returned by the function.
+ assert(processors[option], "The option '" .. option .. "' is not a valid option for this program.")