Examples
DreamCLI's examples pages are generated at build time from the repo's real source examples via dynamic routes.
- Source of truth:
examples/*.ts - Route loader:
docs/examples/[slug].paths.ts - Data loader:
docs/examples/examples.data.ts - Generated example source blocks use
ts twoslashagainst localdreamclisource
Each example gets its own searchable page with usage snippets, hover-enabled source, and related API links. Hover stays scoped to the generated example source blocks; guide pages and shell transcripts remain plain docs. This keeps examples and API docs aligned to the same source model without maintaining separate docs mirrors.
Source-Backed Examples
- Basic single-command CLI. - typed positional args, typed flags, aliases, and default values. (
examples/standalone/basic.ts) - Interactive prompts with config file fallback. - per-flag `.prompt()`, `.env()`, `.config()`, and the full resolution chain (CLI → env → config → prompt → default). (
examples/standalone/interactive.ts) - Mixed machine-readable JSON and human-readable side-channel output. - machine-readable `out.json()` stdout, human-readable stderr side channels, and `--json` for CLI-managed structured errors. (
examples/standalone/json-mode.ts) - Middleware patterns: auth guard, request timing, error handling. - typed middleware context, auth guards, short-circuiting, and wrap-around timing. (
examples/standalone/middleware.ts) - Multi-command CLI with nested command groups (git-like). - top-level commands, nested groups, version metadata, and env-backed flags. (
examples/standalone/multi-command.ts) - Spinner and progress bar usage. - `out.spinner()`, `out.progress()`, `spinner.wrap()`, and automatic suppression in non-TTY or `--json` mode. (
examples/standalone/spinner-progress.ts) - Testing examples using @kjanat/dreamcli/testkit. - `runCommand()`, prompt answers, env/config injection, output assertions, middleware context, and activity assertions. (
examples/standalone/testing.ts)