Commanda 0.3.0
dotnet add package Commanda --version 0.3.0
NuGet\Install-Package Commanda -Version 0.3.0
<PackageReference Include="Commanda" Version="0.3.0" />
<PackageVersion Include="Commanda" Version="0.3.0" />
<PackageReference Include="Commanda" />
paket add Commanda --version 0.3.0
#r "nuget: Commanda, 0.3.0"
#:package Commanda@0.3.0
#addin nuget:?package=Commanda&version=0.3.0
#tool nuget:?package=Commanda&version=0.3.0
Commanda
A lightweight, Cocona-like command line builder for .NET, combining System.CommandLine with the Generic Host (HostBuilder).
Supported target frameworks: net8.0, net9.0, net10.0.
Features
- Fluent registration via
IHostApplicationBuilder - Delegate-based command handlers (sync or async)
- DI parameter injection for reference type parameters
- Automatic binding of primitive/string parameters from CLI
- Support for default help output from System.CommandLine
- Attribute-based options via
[Option](alias inference, descriptions, bool flags)
Quick Start
using Microsoft.Extensions.Hosting;
using Commanda;
var builder = Host.CreateApplicationBuilder(args);
builder.AddCommand("greet", "Say hello", (string name) =>
{
Console.WriteLine($"Hello, {name}!");
});
builder.AddCommand("sum", (int a, int b) =>
{
Console.WriteLine(a + b);
});
var app = builder.Build();
await app.RunCommandsAsync(args);
Run:
dotnet run --project examples/Commanda.Example -- greet Alice
dotnet run --project examples/Commanda.Example -- sum 2 5
Dependency Injection
Any non-primitive, non-string parameter will be resolved from the host service provider.
builder.Services.AddSingleton<GreetingService>();
builder.AddCommand("hello", (GreetingService svc) => svc.SayHello());
Attribute-Based Options
Use [Option] on parameters to turn them into named options with help descriptions. Parameters without [Option] remain positional arguments.
Rules:
- Alias: If
Nameis not specified, the long alias is inferred from the parameter name in kebab-case (e.g.,containerName→--container-name). - Description: Use
Descriptionto populate help text. - Required vs optional: Parameters without a default are required; parameters with a default become optional and use the default when omitted.
- Bool flags:
[Option] boolacts as a switch; presence setstrue. You can also pass--flag falseto override. Default isfalseunless a parameter default is provided.
Example:
builder.AddCommand("hello-opt", async (
GreetingService svc,
[Option(Description = "Name to greet")] string name,
[Option("excited", Description = "Add exclamation (default false)")] bool excited = false
) =>
{
await svc.SayHelloAsync(name);
if (excited) Console.WriteLine("!");
});
Try it:
dotnet run --project examples/Commanda.Example -- hello-opt --name Alice
dotnet run --project examples/Commanda.Example -- hello-opt --name Bob --excited
Installation (Future NuGet)
Planned package id: Commanda.
Versioning & Releases (nbgv CLI)
We use the nbgv CLI and publish on tags. No separate release branches are required.
Install:
dotnet tool install -g nbgv
Set the next development version on main:
# Example: bump to 0.3.0 pre-release
nbgv set-version 0.3.0-alpha
git commit -am "Set version to 0.3.0-alpha"
git push
Create and publish a Release Candidate (on main or a feature branch you plan to release):
# Tag the RC and push the tag
nbgv tag 0.3.0-rc.1
git push origin v0.3.0-rc.1
Publish a stable release:
# Remove pre-release, set the final version, tag, and push
nbgv set-version 0.3.0
git commit -am "Set version to 0.3.0"
nbgv tag 0.3.0
git push origin v0.3.0
CI publishes to nuget.org on tags matching v* using Trusted Publishing (OIDC). Ensure nuget.org Trusted Publishing is configured for this repo/workflow.
Tips:
- Do not move tags after publishing to NuGet; use a new tag (e.g.,
-rc.2) instead. - Make sure your tags use the
vprefix; if so, set"tagPrefix": "v"inversion.json.
Roadmap / Future Enhancements
- Attribute-based command & option metadata
- Sub-commands via grouped classes
- Validation (DataAnnotations)
- Source generator for AOT friendliness
- Middleware / pipeline hooks
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Hosting (>= 10.0.2)
- System.CommandLine (>= 2.0.2)
-
net8.0
- Microsoft.Extensions.Hosting (>= 8.0.1)
- System.CommandLine (>= 2.0.2)
-
net9.0
- Microsoft.Extensions.Hosting (>= 9.0.12)
- System.CommandLine (>= 2.0.2)
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.3.0 | 81 | 1/17/2026 |
| 0.3.0-rc-0001 | 62 | 1/17/2026 |
| 0.2.0 | 97 | 1/17/2026 |