Class Commands.Command
The command class represents a command in game that can be executed with /commandName.
Commands in the Stormwind Library are structured in two parts being:
1. The command operation 2. The command arguments
That said, a command called myAddonCommand that shows its settings screen in dark mode would be executed with /myAddonCommand show darkMode.
Methods
commands.command:getHelpContent () | Returns a human readable help content for the command. |
commands.command:setArgsValidator (value) | Sets the command arguments validator. |
commands.command:setCallback (callback) | Sets the command callback. |
commands.command:setDescription (description) | Sets the command description. |
commands.command:setOperation (operation) | Sets the command operation. |
commands.command:validateArgs (...) | Validates the command arguments if the command has an arguments validator. |
Metamethods
commands.command:__construct () | Command constructor. |
Methods
- commands.command:getHelpContent ()
-
Returns a human readable help content for the command.
Returns:
-
string
a human readable help content for the command
- commands.command:setArgsValidator (value)
-
Sets the command arguments validator.
A command arguments validator is a function that will be executed before the command callback. It must return 'valid' if the arguments are valid or any other value if the arguments are invalid.
Parameters:
- value function the command arguments validator
Returns:
-
self
Usage:
command:setArgsValidator(function(...) -- validate the arguments return 'valid' end)
- commands.command:setCallback (callback)
-
Sets the command callback.
Parameters:
- callback function the callback that will be executed when the command is triggered
Returns:
-
self
- commands.command:setDescription (description)
-
Sets the command description.
Parameters:
- description string the command description that will be shown in the help content
Returns:
-
self
- commands.command:setOperation (operation)
-
Sets the command operation.
Parameters:
- operation string the command operation that will be used to trigger the command callback
Returns:
-
self
- commands.command:validateArgs (...)
-
Validates the command arguments if the command has an arguments validator.
If no arguments validator is set, the method will return 'valid' as by the default, the command must consider the user input as valid to execute. This also allows that addons can validate the arguments internally.
Parameters:
- ... The arguments to be validated
Returns:
-
string
'valid' if the arguments are valid or any other value otherwise