midad run

midad run <file.md|dir> [--listen ADDR] [--watch] [--json] [command args...]

Three things can happen, in this order:

  1. If the file has routes, the server starts and listens. exec runs first.
  2. If a word follows the file name, that command: block runs instead, with args bound to the words after it.
  3. Otherwise the exec block runs, and then the entry function (entry:, or main if there is one).
$ midad run hello.md
hello, world!

$ midad run greet.md hello world
hello world

Flags

flag meaning
--listen ADDR bind another address; it must also be granted by listen
--watch re-run the program when a .md file next to it changes
--json print one object with the program's output in it
--native-handlers compile route handlers to native code (build feature, Unix only)
--no-native-handlers turn that off

--json and --watch do not combine: watch streams a running program.

$ midad run hello.md --json
{
  "command": "run",
  "diagnostics": [],
  "files": 1,
  "ok": true,
  "output": "hello, world!\n",
  "phase": "execute",
  "summary": { "errors": 0, "warnings": 0 }
}

A server

$ midad run app.md
midad: listening on http://127.0.0.1:8787

It stays up until it is killed. MIDAD_WORKERS sets the number of interpreter instances behind the server; MIDAD_WORKERS=1 turns the pool off. A request that finds every instance busy gets 503.

The step budget

The interpreter gives every program a step budget, so a runaway loop stops with an error instead of hanging. An HTTP request gets 50 million steps.

Exit codes

0 when the program ran to the end, 1 when it had a diagnostic or a runtime error, 2 when the command itself was wrong.

On this page