ConsoleCommandAttribute
Marks a command class with its name, optional description, and argument-count behavior. Required on every class inheriting ConsoleCommandBase.
Parameters on the class's single public ExecuteAsync become command arguments; optional ones may be omitted, and ignoreExtraArgs decides whether trailing arguments are accepted.
Usage
using AlmightyShogun.ConsoleCommands;
[ConsoleCommand("status", "Writes the current worker status.")]
public sealed class StatusCommand : ConsoleCommandBase
{
public Task ExecuteAsync()
{
Console.WriteLine("Worker is running.");
return Task.CompletedTask;
}
}using AlmightyShogun.ConsoleCommands;
[Example("production true")]
[ConsoleCommand("deploy", "Deploys a named environment.")]
public sealed class DeployCommand : ConsoleCommandBase
{
public Task ExecuteAsync(string environment, bool force = false)
{
Console.WriteLine($"Deploying {environment}. Force: {force}");
return Task.CompletedTask;
}
}Parameters
name: string
Command name typed by the user in the console input, matched case-insensitively. Must not be blank or contain whitespace, since input is split on spaces before the first token is matched.
description: string?
The one-line explanation surfaced as Description on ConsoleCommand for a help listing.
Default: null
ignoreExtraArgs: bool
Whether extra input arguments are discarded instead of treated as an invalid argument count. It relaxes only the upper bound, so a command still refuses to run when too few arguments are supplied to fill its required parameters.
Default: false
Type signature
public ConsoleCommandAttribute(
string name,
string? description = null,
bool ignoreExtraArgs = false
);