Commands
Commands are the core of any CLI built with Nullean.Argh. The framework supports three registration forms, all fully supported by the source generator.
app.Map("deploy", DeployHandlers.Run);
app.Map("greet", (string name) => Console.WriteLine($"Hello, {name}!"));
app.Map<StorageHandlers>();
- Method group - direct typed dispatch.
- Lambda - convenient for simple one-liners.
- Class - registers every public method on
Tas a command.
Tip
With class and method-group registration, XML doc comments on your handler methods flow directly into --help output. Lambdas skip that path.
| API | Purpose |
|---|---|
Map(name, handler) |
Bind a command name to a delegate. |
Map<T>() |
Register every public method on T as a command (typically a static class of handlers). |
MapRoot(handler) |
Default handler when no subcommand is given (at app root, or inside a MapNamespace callback for that namespace). |
Flat apps route app <command> … while hierarchical apps route app <namespace> … <command> …. The generator emits the switch/dispatch tree accordingly.
For programmatic route inspection, ArghParser.Route(args) returns a RouteMatch (CommandPath, RemainingArgs) without invoking handlers. This is useful for tests and tooling.
- Registration - detailed registration patterns
- Namespaces - grouping commands under shared paths