Adds Spectre.Console CommandApp extensions for Microsoft.Extensions.Hosting.
Install the Spectre.Console.Extensions.Hosting NuGet package into your app.
Install-Package Spectre.Console.Extensions.Hosting
After the installation you can use the extension UseSpectreConsole
for IHostBuilder.
For this you must configure the SpectreConsole CommandApp in your application`s Program.cs file:
public static async Task<int> Main(string[] args)
{
await Host.CreateDefaultBuilder(args)
.UseConsoleLifetime()
.UseSpectreConsole<DefaultCommand>()
.ConfigureServices(
(_, services) => { services.AddSingleton<IGreeter, HelloWorldGreeter>(); })
.RunConsoleAsync();
return Environment.ExitCode;
}
It is also possible to customize the command configurations:
Host.CreateDefaultBuilder(args)
...
.UseSpectreConsole(config =>
{
config.AddCommand<AddCommand>("add");
config.AddCommand<CommitCommand>("commit");
config.AddCommand<RebaseCommand>("rebase");
#if DEBUG
config.PropagateExceptions();
config.ValidateExamples();
#endif
})
...
Examples are located in the samples folder. It is planned to further adopt CLI examples from Spectre.Console.
Jürgen Rosenthal-Buroh @JuergenRB
pectre.Console.Extensions.Hosting follows the Contributor Covenant Code of Conduct.
We accept Pull Requests.
Small note: If editing the Readme, please conform to the standard-readme specification.