Console app quick start
The simplest way to use Nullean.Argh - no dependencies, no host, just a CLI.
-
Add the package reference
<ItemGroup> <PackageReference Include="Nullean.Argh" /> </ItemGroup> -
Create a minimal CLI
using Nullean.Argh; var app = new ArghApp(); app.Map("hello", MyHandlers.SayHello); return await app.RunAsync(args);- Create a new
ArghAppinstance. - Register a command named
hellobound to a method group. - Dispatch into generated code. The source generator emits parsing, routing, and dispatch logic at build time.
- Create a new
-
Run it
dotnet run -- hello
All three registration forms are supported:
using Nullean.Argh;
var app = new ArghApp();
app.Map("deploy", DeployHandlers.Run);
app.Map("greet", (string name) => Console.WriteLine($"Hello, {name}!"));
app.Map<StorageHandlers>();
return await app.RunAsync(args);
- Method group - direct typed dispatch.
- Lambda - convenient for simple one-liners.
- Class - registers every public method on
Tas a command.
Use MapRoot to define a handler that runs when no subcommand is given:
var app = new ArghApp();
app.MapRoot(Handlers.DefaultAction);
app.Map("deploy", Handlers.Deploy);
return await app.RunAsync(args);
For apps without a root command, use UseCliDescription to set a one-liner shown beneath the Usage: line in --help:
app.UseCliDescription("Manage and deploy your application's cloud resources.");
Important
UseCliDescription cannot be combined with MapRoot. If you have a root command, put the description in its XML doc <summary> instead.