Method Execute
- Namespace
- Ploch.CommandLine.Spectre.Commands
- Assembly
- Ploch.CommandLine.Spectre.dll
Execute(CommandContext, TSettings, CancellationToken)
Executes the command with the specified context and settings.
public override int Execute(CommandContext context, TSettings settings, CancellationToken cancellationToken)
Parameters
contextCommandContextThe command context containing execution information.
settingsTSettingsThe settings to use for command execution.
cancellationTokenCancellationTokenA token that is forwarded to DoExecute(CommandContext, TSettings, CancellationToken) so implementations can honour cancellation.
Returns
- int
An integer representing the exit code of the command execution.
Remarks
The settings are passed through the configured settings processor before DoExecute(CommandContext, TSettings, CancellationToken) runs.
Exceptions raised by the settings processor or by DoExecute(CommandContext, TSettings, CancellationToken) do not propagate: they are passed to the configured
IExceptionHandler, whose result becomes the exit code; a handler that throws surfaces as
ExceptionHandlerFailedException, which the application's Spectre handler reports once and turns into
Error. An OperationCanceledException thrown while
cancellationToken has cancellation requested is the exception to that rule: it is treated as the requested
outcome and returns Cancelled without reaching the handler. An OperationCanceledException
raised while that token is still live - a TaskCanceledException from an HttpClient timeout, or an inner
token the implementation created and cancelled itself - is a fault nobody asked for and goes to the handler like any other
exception.
Exceptions
- ArgumentNullException
Thrown when context or settings is null.
- ExceptionHandlerFailedException
Thrown when the configured IExceptionHandler itself throws while handling an exception; the handler's exception is its InnerException and the exception being handled is Original.