Skip to content

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.

  1. Create a console project

    Terminal window
    dotnet new console -n HelloRepl
    cd HelloRepl
    dotnet add package Repl
  2. Replace Program.cs

    using Repl;
    var app = ReplApp.Create().UseDefaultInteractive();
    app.Map("hello", () => "world");
    return app.Run(args);
  3. Run in CLI mode

    Terminal window
    dotnet run -- hello
    # world
  4. Run in REPL mode

    Terminal window
    dotnet run
    # > hello
    # world
    # > exit
  5. Get help for free

    Terminal window
    dotnet run -- --help
    # Commands:
    # hello
  • 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 if args is non-empty, REPL otherwise.

No argument-parsing library. No interactive-loop wiring. No output formatting.

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 Alice
Hello, Alice!
$ myapp add 3 4
7

Route constraints like :int, :email, :guid are validated at parse time — invalid input is rejected before your handler runs.

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 1
Id Name Email
1 Alice alice@example.com
$ myapp contact 1 --json
{ "id": 1, "name": "Alice", "email": "alice@example.com" }
  • CLI Mode — output formats, help, shell completion
  • REPL Mode — scoped navigation, history, autocomplete
  • MCP Mode — expose commands to AI agents