Kritikos.SpectreCli.Infrastructure
0.1.10
dotnet add package Kritikos.SpectreCli.Infrastructure --version 0.1.10
NuGet\Install-Package Kritikos.SpectreCli.Infrastructure -Version 0.1.10
<PackageReference Include="Kritikos.SpectreCli.Infrastructure" Version="0.1.10" />
paket add Kritikos.SpectreCli.Infrastructure --version 0.1.10
#r "nuget: Kritikos.SpectreCli.Infrastructure, 0.1.10"
// Install Kritikos.SpectreCli.Infrastructure as a Cake Addin #addin nuget:?package=Kritikos.SpectreCli.Infrastructure&version=0.1.10 // Install Kritikos.SpectreCli.Infrastructure as a Cake Tool #tool nuget:?package=Kritikos.SpectreCli.Infrastructure&version=0.1.10
Spectre.Hosting
An opinionated set of extensions and infrastructure for the excelent Spectre.Console.Cli, mainly covering the integration with Dependency Injection and logging via Serilog.
Usage
CommandBuilder and Extensions
Creates a CommandApp
with a fluent builder pattern, with the following options provided:
- Using
ICommandAppStartup
for configuration:public class CommandStartup : ICommandStartup { ... } var app = CommandBuilder.CreateDefaultBuilder() .UseStartup<CommandStartup>;
- Make all
CommandSettings
available for dependency injection:public class CommandStartup : ICommandStartup { ... } var app = CommandBuilder.CreateDefaultBuilder() .RegisterSettingsFromAssemblyContaining<CommandStartup>(); // OR var app = CommandBuilder.CreateDefaultBuilder() .RegisterSettingsFromAssembly(typeof(CommandStartup).Assembly);
- Adds logging to file via Serilog:
// Additionally, make sure your CommandSettings inherit from LogCommandSettings // in order to include the verbosity level and the path to the log file var app = CommandBuilder.CreateDefaultBuilder() .AddFileLogging();
For ease of use, the extension method CommandBuilder.CreateDefaultCommandApp<T>()
is provided, where T
is an implementation of ICommandStartup
. This method will ensure you get a command app with all the above options enabled. A sample implementation follows:
public class Startup : ICommandAppStartup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddRefitClient<IAzureDevOpsApi>(_=>new RefitSettings(), string.Empty);
}
public void Configure(IConfigurator appConfiguration)
{
ArgumentNullException.ThrowIfNull(appConfiguration);
appConfiguration
.SetApplicationName("devops-cli")
.CaseSensitivity(CaseSensitivity.None);
appConfiguration.AddCommand<FooCommand>("foo");
}
}
Dependency Injection
Provide a proper IServiceCollection
implementation to TypeRegistrar
and use it when constructing your CommandApp
:
var services = new ServiceCollection();
var app = new CommandApp(new TypeRegistrar(services));
Logging
Predefined logging settings include settable verbosity at run time and logging to a file writer.
Alternatively, create your own implementations of the above classes.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Kritikos.SpectreCli.Logging (>= 0.1.10)
- Serilog.Extensions.Logging (>= 7.0.0)
- Serilog.Sinks.File (>= 5.0.0)
- Serilog.Sinks.Map (>= 1.0.2)
- Spectre.Console.Cli (>= 0.47.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.10 | 500 | 9/27/2023 |