Skip to content

CLI Mode

When you pass arguments to your app, Repl dispatches the command and exits — standard CLI behavior.

Terminal window
myapp <route> [arguments] [options]

Examples:

Terminal window
myapp client list
myapp client 42 show
myapp client 42 show --json

Every command supports output format flags out of the box:

FlagOutput
(none)Human-readable text / table
--jsonJSON
--xmlXML
--yamlYAML
--markdownMarkdown table
Terminal window
$ myapp contacts list --json
[
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]

--help is built in at every level:

Terminal window
$ myapp --help
Commands:
client
report
$ myapp client --help
Commands:
client list
client {id} show
client {id} remove

Help also lists a Global Options: section covering the built-in flags and any custom global options you registered, with their descriptions.

Register Repl’s completion scripts to get tab completion in your shell:

Terminal window
# Auto-detect current shell
myapp completion install
# Explicit shell
myapp completion install --shell bash
myapp completion install --shell powershell
myapp completion install --shell zsh
myapp completion install --shell fish
myapp completion install --shell nu # Nushell

This writes a managed block to the shell’s profile file. Tab completion then works for all routes, context segments, and option names.

Run these commands through the app’s own executable (myapp completion install), which works wherever .NET is installed. A setup started as dotnet myapp.dll is accepted, but the PowerShell completer it writes is registered for dotnet as well as myapp, and runs dotnet completion __complete without the DLL: myapp gets no completions, and completing a dotnet command line shows dotnet error text instead. To repair such a setup, run myapp completion install --shell powershell --force from the executable, then open a new shell.

What completion returns:

  • Command literals and context segments from your graph.
  • The route’s own options, plus static global options (--help, --interactive, --no-interactive, --no-logo, output aliases, --output:<format>, --answer:<name>, and the result-flow flags --result:page-size, --result:cursor, --result:pager, --result:all).
  • Enum member names for a pending enum-typed option.
  • .WithCompletion(...) provider values — opt-in per provider.

Every shell Tab spawns a new process and blocks the shell until the app answers, so a slow completion provider (network, database) must never run there implicitly. A provider only serves shell completion when its registration opts in:

app.Map("contact inspect {clientId}", (string clientId) => Inspect(clientId))
.WithCompletion(
"clientId",
(ctx, input, ct) => LookupClientIdsAsync(input, ct),
CompletionProviderScope.InteractiveAndShell);

The default scope (CompletionProviderScope.Interactive) keeps the provider on in-process surfaces only: the interactive Tab menu and the complete ambient command. Each provider invocation is also bounded by ShellCompletionOptions.ProviderTimeout (default: 1 second) — a stalled provider degrades completion to the static candidates instead of blocking the shell.

Shell completion and the interactive REPL autocomplete draw candidates from the same source and parse prior tokens the same way. Two deliberate differences remain: on an empty token after a complete command, shell completion lists option names while the interactive menu shows parameter placeholders (options appear from the first typed -); and the interactive menu runs every registered provider while the shell bridge only runs opted-in ones.

Other commands:

Terminal window
myapp completion status # show current installation status
myapp completion uninstall # remove the managed block
myapp completion detect-shell # show which shell was detected

The completion bridge (completion __complete) is hidden from --help — it is a protocol command used by the shell scripts.

Automatic installation — configure how completion is offered at startup:

SetupModeBehavior
Manual (default)User runs install explicitly
PromptOffers installation once on the first interactive startup
AutoInstalls automatically when a supported shell is detected
app.Options(o =>
{
o.ShellCompletion.SetupMode = CompletionSetupMode.Prompt;
});

Any argument prefixed with @ is a response file:

Terminal window
myapp @deploy.rsp

deploy.rsp:

deploy
--environment
production
--region
us-east-1

Tokens are read one per line. Useful for long or repeatable invocations, and for passing arguments in CI without quoting issues. Response files are not recursive.

Add --help --json to get a structured help payload — useful for agents and tooling:

Terminal window
$ myapp client --help --json
{
"name": "client",
"commands": [
{ "route": "list", "description": "..." },
{ "route": "{id:int} show", "description": "..." }
]
}
ConditionExit code
Success, --help0
Refusal before the handler runs — unknown command, invalid option, an argument that cannot be bound2
Handler failure — Results.Error, Results.Validation, Results.NotFound, Results.Cancelled, an unhandled exception1
Ran to completion with failures — Results.CompletedWithFailures(report)1
Interrupted by Ctrl+C or SIGTERM, under UseCliProfile() or UseDefaultInteractive()130 or 143
Custom (explicit)any N — return Results.Exit(N) from a handler

Every code except Results.Exit(N) comes from one table, ReplOptions.ExitCodes, so an application can change any of them in one place. See Exit Codes & Signals for the full outcome model.

→ REPL Mode