Table of Contents

Method ExecuteAsync

Namespace
Ploch.CommandLine.Spectre.Commands
Assembly
Ploch.CommandLine.Spectre.dll

ExecuteAsync(CommandContext, TSettings, CancellationToken)

Executes the command asynchronously with the provided context and settings.

public override Task<int> ExecuteAsync(CommandContext context, TSettings settings, CancellationToken cancellationToken)

Parameters

context CommandContext

The command context containing execution information.

settings TSettings

The settings to use for command execution.

cancellationToken CancellationToken

A token that is forwarded to DoExecuteAsync(CommandContext, TSettings, CancellationToken) so implementations can honour cancellation.

Returns

Task<int>

An integer representing the exit code of the command execution.

Remarks

The settings are passed through the configured settings processor before DoExecuteAsync(CommandContext, TSettings, CancellationToken) runs. Exceptions raised by the settings processor or by DoExecuteAsync(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.