Added cancelling to the wiki.
parent
270a0681a0
commit
89373c22ae
39
Commands.md
39
Commands.md
@ -2,7 +2,7 @@
|
||||
Commands are methods inside a [module](Modules) that the shell will execute when a command that fits its module ID (if applicable) and name ID is run. A command can have as many parameters as required and the types for those parameters vary.
|
||||
|
||||
## How to Use
|
||||
Commands must be in a [module](Modules) to be recognized. Any commands not inside their respective modules will be ignored. Commands are declared by applying the `CommandAttribute` attribute in the namespace `SrcMod.Shell.Modules.ObjectModels` to a method. The method can be static. The return type must be `void` and all parameters must have the following types:
|
||||
Commands must be in a [module](Modules) to be recognized. Any commands not inside their respective modules will be ignored. Commands are declared by applying the `CommandAttribute` attribute in the namespace `SrcMod.Shell.Modules.ObjectModels` to a method. The method can be static and must always have a body. The return type must be `void` and all parameters must have the following types:
|
||||
|
||||
| Type |
|
||||
|-|
|
||||
@ -26,6 +26,7 @@ Commands must be in a [module](Modules) to be recognized. Any commands not insid
|
||||
| `System.DateOnly` |
|
||||
| `System.DateTime` |
|
||||
| `System.DateTimeOffset` |
|
||||
| `System.Enum` |
|
||||
| `System.Guid` |
|
||||
| `System.TimeOnly` |
|
||||
| `System.TimeSpan` |
|
||||
@ -62,12 +63,46 @@ public static class ExampleModule2
|
||||
[Command("test")]
|
||||
public static void ExampleCommand()
|
||||
{
|
||||
// Invoked by executing "example command" *or*
|
||||
// Invoked by executing "example command" or
|
||||
// "example test"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
SrcMod allows the user to terminate commands prematurely by pressing the terminal cancel key (Ctrl+C or Ctrl+Break on Windows Terminal). However, this can be overriden by adding the `CanCancelAttribute` attribute to your command. The attribute takes in a boolean that represents whether it can be cancelled or not. A value of `true` means it can be cancelled. If a `CanCancelAttribute` attribute is not provided, it is assumed that the command *does* support cancelling.
|
||||
|
||||
Here is an example:
|
||||
```csharp
|
||||
// Used for the `CommandAttribute` and `ModuleAttribute`.
|
||||
using SrcMod.Shell.Modules.ObjectModels;
|
||||
|
||||
[Module("example")]
|
||||
public static class ExampleModule3
|
||||
{
|
||||
[Command("command1")]
|
||||
public static void ExampleCommandA()
|
||||
{
|
||||
// This command CAN be cancelled.
|
||||
}
|
||||
|
||||
[Command("command2")]
|
||||
[CanCancel(false)]
|
||||
public static void ExampleCommandB()
|
||||
{
|
||||
// This command CANNOT be cancelled.
|
||||
}
|
||||
|
||||
[Command("command3")]
|
||||
[CanCancel(true)]
|
||||
public static void ExampleCommandC()
|
||||
{
|
||||
// This command CAN be cancelled.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If a user of the shell attempts to cancel a command that does not support cancelling, an error sound will play.
|
||||
|
||||
---
|
||||
|
||||
## Default Commands
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user