Table of Contents

Class CommandAppExecutor

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

Implements the ICommandAppExecutor interface to execute command-line applications.

public class CommandAppExecutor : ICommandAppExecutor
Inheritance
CommandAppExecutor
Implements
Inherited Members

Remarks

The token is taken rather than the CancellationTokenSource behind it. This type only ever observes cancellation, it never requests it, so it has no use for the source. Taking the token also decouples execution from the source's lifetime: Token throws ObjectDisposedException once the source is disposed, whereas a token captured beforehand stays usable.

An executor permits one execution attempt. An attempt may build the host behind the type registrar, and Build() cannot be called again, so every attempt consumes the executor whatever its outcome: a second Run(params IEnumerable<string>) or RunAsync(params IEnumerable<string>) is rejected up front with an InvalidOperationException. Running again takes a new executor over a freshly configured command application; ConfigureCommandApp(Action<IConfigurator>) does both when the application was built through AppBuilder. An executor constructed directly wraps an Spectre.Console.Cli.ICommandApp the caller owns, so the caller configures a new one.

For an executor returned by ConfigureCommandApp(Action<IConfigurator>), a run that reaches command resolution builds the host for dependency injection, configuration and logging — a parse failure or --version returns before any host exists. The library never starts the host, so a registered IHostedService does not run, and a host that was built is disposed when the run ends. See the remarks on ConfigureCommandApp(Action<IConfigurator>).

Constructors

CommandAppExecutor(ICommandApp, CancellationToken)

Implements the ICommandAppExecutor interface to execute command-line applications.

Methods

Run(params IEnumerable<string>)

Executes the command-line application synchronously with the specified arguments.

RunAsync(params IEnumerable<string>)

Executes the command-line application asynchronously with the specified arguments.