CommandService
A static class in Root.Township, Alta.Console.
Static entry point for the console command system. Parses a command line, finds the best matching command in the collection and runs it.
- Listed in Console, logging and analytics
- Documented in Writing commands, Console, utilities and Alta assemblies
Fields
3 private and internal fields
| Member | What it is |
|---|---|
private static CommandCollection collection | Cached collection behind CommandCollection. |
private static CommandContext defaultContext | Context made for the logged-in user, used when Handle gets no context. |
private static readonly Logger logger | Logger for this class. |
Properties
| Member | What it is |
|---|---|
static CommandCollection CommandCollection { get; } | All commands, collected from this assembly on first use. |
static CommandContext CurrentContext { get; private set; } | The context of the command being run (or last run). |
static Action<CommandSearchResult> CustomHandler { get; set; } | One-shot handler: if set, the next matched command is passed to it instead of being run. It is cleared on every Handle call. |
static CommandSearchResult LastCommand { get; private set; } | The last command passed to HandleMatchedCommand. |
Methods
| Member | What it is |
|---|---|
static async Task<CommandResult> Handle(string command, CommandContext context = null) | Parses and runs a command line. With no context it uses a default one for the logged-in API user. Returns an error result with suggestions if nothing matches. |
static async Task<CommandResult> HandleMatchedCommand(CommandSearchResult matchedCommand) | Runs an already matched command, logs its result and turns exceptions into error results. |
static CommandSearchResult[] Search(CommandCollection collection, string search, CommandContext context) | Splits a command line into words (quotes group words, backslash escapes quotes) and searches the collection for matches. |
static void ThrowError(string format, params object[] arguments) | Throws a CommandException with a formatted message, which HandleMatchedCommand turns into an error result. |