Command
A class in Root.Township, Alta.Console.
One console command built from a method with a CommandAttribute. Matches typed words against its name and parameters and calls the method. The method is called with no instance, so it must be static.
- Listed in Console, logging and analytics
- Inherits or implements
CommandPart - Documented in Writing commands, Health and damage
Constructors
| Member | What it is |
|---|---|
Command(MethodInfo method, Module parent, CommandAttribute attribute) | Creates a Command from method, parent and attribute. |
Fields
3 private and internal fields
Properties
| Member | What it is |
|---|---|
CommandAttribute Attribute { get; set; } | The CommandAttribute the command was made from. |
Func<ProgressiveHandler, object[], Task<CommandResult>> InvokeCommand { get; private set; } | Calls the method with converted arguments and wraps what it returns (awaiting tasks) in a CommandResult. |
bool IsLoggingValueAsTable { get; set; } | Whether the result is logged as a table. |
bool IsProgressive { get; set; } | Progressive commands are not supported; invoking one returns an error result. |
MethodInfo Method { get; } | Meant to be the method behind the command, but never set in this build, so it is null. |
List<Parameter> Parameters { get; } | The command's parameters. A last string or array parameter takes all remaining words. |
Type ReturnType { get; } | What the method returns, with Task unwrapped; void for none. |
Methods
| Member | What it is |
|---|---|
override string ToString() | Full command path followed by its parameters. |
protected override IEnumerable<CommandPart> GetCommandPartInternal(string[] lower, string[] cased, int index, CommandContext context) (iterator) | Returns this command if the words end at its name. |
protected override IEnumerable<CommandSearchResult> GetCommandsInternal(string[] lower, string[] cased, int index, CommandContext context) (iterator) | Tries to match the words after the command name to its parameters and returns the result. |
3 private and internal methods
| Member | What it is |
|---|---|
private CommandSearchResult AreParametersViable(string[] lower, string[] cased, int index) | Checks the argument count against the parameters and converts them. A last string or array parameter takes the rest. |
private bool AttemptConvertArguments(int matchedCount, string[] argumentParts, int index, object[] convertedArguments) | Converts each argument with its parameter type's converter. Fails on a null result unless AllowNull is set. |
private async Task<CommandResult> Invoke(ProgressiveHandler progressivehandler, object[] args) | Calls the command method with no instance (so it must be static) and wraps what it returns in a CommandResult. Progressive commands return an error. |
Used in
Members of other types that take, return or hold a Command:
CommandCollection.GetParams, CommandCollection.ProcessParam, CommandResult.Command, CommandResult.CommandResult, CommandResult.ErrorResult, CommandResult.VoidResult, CommandResult<T>.CommandResult<T>, BaseCommands.LogCommand, CommandSearchResult.command, CommandSearchResult.CommandSearchResult, CommandSearchResult.IncorrectParameterTypes, CommandSearchResult.NotEnoughParameters, CommandSearchResult.ParameterParsingFailure, CommandSearchResult.Success, CommandSearchResult.TooManyParameters, DynamicCommandResult.DynamicCommandResult, Module.Commands, Parameter.Command, Parameter.Parameter.