Skip to content

Latest commit

 

History

History
74 lines (49 loc) · 2.11 KB

README.md

File metadata and controls

74 lines (49 loc) · 2.11 KB

SpectreConsoleHost

NuGet Version

A Generic Host builder and extensions for Spectre.Console

Examples

Extension Methods

Calling the AddSpectreConsole service collection extension methods will add a Spectre.Console command app to be executed.

The extension methods can be called multiple times to add multiple apps to be executed, although this is generally not recommended.

The application will exit once all the added command apps complete execution with the exit code being set by the last command app to finish execution.

Basic Usage

No default command

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Services.AddSpectreConsole(args, configurator =>
{
    configurator.AddCommand<ExampleCommand>("example");
});

await builder.Build().RunAsync();

Default command

Without additional configuration

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Services.AddSpectreConsole<DefaultCommand>(args);

await builder.Build().RunAsync();

With additional configuration

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Services.AddSpectreConsole<DefaultCommand>(args, configurator =>
{
    configurator.AddCommand<ExampleCommand>("example");
});

await builder.Build().RunAsync();

Host Builder

The host builder adds a command app with the configuration from the builders Configurator property.

Basic usage

No default command

SpectreConsoleHostBuilder builder = SpectreConsoleHost.CreateBuilder(args);

builder.Configurator.AddCommand<SomeCommand>("somecommand");

await builder.Build().RunAsync();

Default command

SpectreConsoleHostBuilder builder = SpectreConsoleHost.CreateBuilder<DefaultCommand>(args);

builder.Configurator.AddCommand<SomeCommand>("somecommand");

await builder.Build().RunAsync();