Console app quick start

The simplest way to use Nullean.Argh - no dependencies, no host, just a CLI.

  1. Add the package reference

    Xml
    <ItemGroup>
      <PackageReference Include="Nullean.Argh" />
    </ItemGroup>
    
  2. Create a minimal CLI

    C#
    using Nullean.Argh;
    
    var app = new ArghApp();
    app.Map("hello", MyHandlers.SayHello);
    
    return await app.RunAsync(args);
    
    1. Create a new ArghApp instance.
    2. Register a command named hello bound to a method group.
    3. Dispatch into generated code. The source generator emits parsing, routing, and dispatch logic at build time.
  3. Run it

    Shell
    dotnet run -- hello
    

All three registration forms are supported:

C#
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);
  1. Method group - direct typed dispatch.
  2. Lambda - convenient for simple one-liners.
  3. Class - registers every public method on T as a command.

Use MapRoot to define a handler that runs when no subcommand is given:

C#
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:

C#
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.