Skip to content

juro-org/Spectre.Console.Extensions.Hosting

Repository files navigation

Spectre.Console.Extensions.Hosting

standard-readme compliant Contributor Covenant Build NuGet package

Adds Spectre.Console CommandApp extensions for Microsoft.Extensions.Hosting.

Table of Contents

Install

Install the Spectre.Console.Extensions.Hosting NuGet package into your app.

Install-Package Spectre.Console.Extensions.Hosting

Usage

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

Examples are located in the samples folder. It is planned to further adopt CLI examples from Spectre.Console.

Maintainer

Jürgen Rosenthal-Buroh @JuergenRB

Contributing

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.

License

MIT License © Jürgen Rosenthal-Buroh