command.arg - Windower/packages GitHub Wiki

This library handles argument descriptors for use inside Windower's command library.

local command = require('command')

local arg = command.arg

The arg table has the following entries:


command.arg.register

Stores an argument object, which can then be used when registering functions.

Definition

function command.arg.register(name : string, argument : argument_object or string)

Parameters

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))

Return

This function does not return any values.



command.arg.register_type

Registers a new argument type to use with command.arg.parse, and by extension when registering arguments or commands.

Definition

function command.arg.register_type(name : string, arg_type : argument_type)

Parameters

name string

The name under which to register this argument type.

arg_type argument_type

A table containing the definitions for this type.

Return

This function does not return any values.



command.arg.parse

Creates a new argument object, which can then be used when registering functions.

Definition

function command.arg.parse(description : string) : argument_object

Parameters

description string

The description of the argument. This is a string of the following format:

name:type(options)=default

The 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. The options are not required and what they do depends on the type. 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 match pattern.
  • 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 the min and max values.
  • integer(min,max): Same as number(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

Return

argument_object argument_object

The argument object parsed from the given description. Can be used when registering functions.

⚠️ **GitHub.com Fallback** ⚠️