-
Notifications
You must be signed in to change notification settings - Fork 20
command.arg
This library handles argument descriptors for use inside Windower's command library.
local command = require('command')
local arg = command.argThe arg table has the following entries:
- command.arg.register : Registers a new argument
- command.arg.register_type : Registers a new argument type
- command.arg.parse : Returns an argument descriptor parsed from a string
Stores an argument object, which can then be used when registering functions.
function command.arg.register(name : string, argument : argument_object or string)name string
The name under which to store the argument object.
argument argument_object or string
This parameter is either an argument descriptor or a string which can be parsed by command.arg.parse. In the latter case, that is exactly what will happen internally and it is meant as a convenience. The following are equivalent:
command.arg.register(name, arg_string) command.arg.register(name, command.arg.parse(arg_string))
This function does not return any values.
Registers a new argument type to use with command.arg.parse, and by extension when registering arguments or commands.
function command.arg.register_type(name : string, arg_type : argument_type)name string
The name under which to register this argument type.
arg_type argument_type
A table containing the definitions for this type.
This function does not return any values.
Creates a new argument object, which can then be used when registering functions.
function command.arg.parse(description : string) : argument_objectdescription string
The description of the argument. This is a string of the following format:
name:type(options)=defaultThe string is further enclosed in either
<>to denote a required parameter or[]to denote an optional parameter, optional parameters must come after all required parameters. Theoptionsare not required and what they do depends on thetype. The following types and options are available by default (more can be added dynamically with command.arg.register_type):
string(pattern): A string parameter which must matchpattern.text(): Will treat all remaining arguments as one large text, concatenating the remaining arguments by a space.number(min,max): Will parse the parameter to a number and check if it's between theminandmaxvalues.integer(min,max): Same asnumber(min,max)but also checks that the number is an integral value.one_of(...): Checks if the parameter is one of the provided values.Some examples:
'<foo>' -- A required argument named `foo` '<foo:number>' -- A required parameter named `foo` and of type `number` '[foo:integer(200,500)]' -- An optional parameter named `foo` and of type `number`, -- between 200 and 500 '<foo:string(%a+)>*' -- At least one required parameter named `foo`, needs to match -- the given pattern `%a+`, i.e. needs to be an all-letter token '[foo:one_of(a,b)=a]' -- An optional parameter named `foo`, either `'a'` or `'b'`, -- defaults to `'a'` if not provided
argument_object argument_object
The argument object parsed from the given description. Can be used when registering functions.