Your First App
This tutorial builds the smallest useful Repl app — a hello command that runs as both a CLI tool and an interactive REPL.
-
Create a console project
Terminal window dotnet new console -n HelloReplcd HelloRepldotnet add package Repl -
Replace
Program.csusing Repl;var app = ReplApp.Create().UseDefaultInteractive();app.Map("hello", () => "world");return app.Run(args); -
Run in CLI mode
Terminal window dotnet run -- hello# world -
Run in REPL mode
Terminal window dotnet run# > hello# world# > exit -
Get help for free
Terminal window dotnet run -- --help# Commands:# hello
What just happened
Section titled “What just happened”ReplApp.Create()wires up the DI container, routing, and output pipeline.UseDefaultInteractive()activates the interactive REPL when no arguments are given.app.Map("hello", () => "world")registers a route. The return value is rendered automatically.app.Run(args)dispatches: CLI ifargsis non-empty, REPL otherwise.
No argument-parsing library. No interactive-loop wiring. No output formatting.
Typed parameters
Section titled “Typed parameters”Routes accept typed parameters directly:
app.Map("greet {name}", (string name) => $"Hello, {name}!");app.Map("add {a:int} {b:int}", (int a, int b) => a + b);$ myapp greet AliceHello, Alice!
$ myapp add 3 47Route constraints like :int, :email, :guid are validated at parse time — invalid input is rejected before your handler runs.
Structured output
Section titled “Structured output”Return any object and Repl renders it:
record Contact(int Id, string Name, string Email);
app.Map("contact {id:int}", (int id) => new Contact(id, "Alice", "alice@example.com"));$ myapp contact 1Id Name Email1 Alice alice@example.com
$ myapp contact 1 --json{ "id": 1, "name": "Alice", "email": "alice@example.com" }