![]() |
VOOZH | about |
dotnet add package Albatross.CommandLine --version 8.0.14
NuGet\Install-Package Albatross.CommandLine -Version 8.0.14
<PackageReference Include="Albatross.CommandLine" Version="8.0.14" />
<PackageVersion Include="Albatross.CommandLine" Version="8.0.14" />Directory.Packages.props
<PackageReference Include="Albatross.CommandLine" />Project file
paket add Albatross.CommandLine --version 8.0.14
#r "nuget: Albatross.CommandLine, 8.0.14"
#:package Albatross.CommandLine@8.0.14
#addin nuget:?package=Albatross.CommandLine&version=8.0.14Install as a Cake Addin
#tool nuget:?package=Albatross.CommandLine&version=8.0.14Install as a Cake Tool
A .NET library that simplifies creating command-line applications with System.CommandLine. It provides automatic code generation and dependency injection support while maintaining full access to System.CommandLine's capabilities. The framework is opinionated toward async actions with out-of-the-box support for cancellation and graceful shutdown.
Designed for enterprise CLI applications, Albatross.CommandLine enforces consistent async patterns, built-in dependency injection, and graceful shutdown handling. These opinionated choices reduce complexity and ensure scalability from simple utilities to complex enterprise workflows.
System.CommandLine and Microsoft.Extensions.Hosting.System.CommandLine when neededOption and Argument classes and use [UseOption<T>] and [UseArgument<T>] attributes to compose them into commands with automatic code generation[OptionHandler] attribute for pre-processing and input transformation patterns. Execute database validation, API calls, or transform simple inputs into complex objects before command executionCommandHost.ConfigureHost() to bootstrap additional services, or use Albatross.CommandLine.Defaults for pre-configured Serilog logging and JSON/environment configuration supportCreate a console app. In the program.cs file, insert the code below:
internal class Program {
static async Task<int> Main(string[] args) {
await using var host = new CommandHost("Sample Command Line Application")
.RegisterServices(RegisterServices)
// this method is generated by source generator
// this line will not compile before the creation of the first command
.AddCommands()
.Parse(args)
.Build();
return await host.InvokeAsync();
}
static void RegisterServices(ParseResult result, IConfiguration configuration, IServiceCollection services) {
// RegisterCommands method is generated by codegen
services.RegisterCommands();
// register the rest of the dependency here
...
}
}
[Verb<HelloWorldCommandHandler>("hello", Description = "The HelloWorld command")]
public record class HelloWorldParams {
[Option]
public required string Name { get; init; }
}
The Command Handler has to inherit interface: IAsyncCommandHandler
public class HelloWorldCommandHandler : IAsyncCommandHandler {
ParseResult result;
HelloWorldParams parameters;
ILogger logger;
public HelloWorldCommandHandler(ParseResult result, HelloWorldParams parameters, ILogger<HelloWorldCommandHandler> logger) {
this.result = result;
this.parameters = parameters;
this.logger = logger;
}
public async Task<int> InvokeAsync(CancellationToken cancellationToken) {
// do your work here
await Console.WriteLineAsync($"{result} is invoked with {parameters}");
return 0;
}
}
Usage: dotnet run -- hello --name test
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 3 NuGet packages that depend on Albatross.CommandLine:
| Package | Downloads |
|---|---|
|
Albatross.CommandLine.Defaults
Package Description |
|
|
Albatross.CommandLine.Inputs
Package Description |
|
|
Albatross.EFCore.Admin
Package Description |
This package is not used by any popular GitHub repositories.