Wit

CLI reference

Every wit subcommand, flag, exit code and environment variable. Source: packages/cli/src/.

Synopsis

wit parse <file>
wit check <file>… [--template name] [--sources wit.sources.json --allow-exec] [--env .env]
wit fmt <file> [-w|--write | --check]
wit build <file> [-o out.html|out.md|out.pdf] [--format html|md|pdf] [--raw | --fragment]
                 [--template name] [--paper a4|a5|letter|legal]
                 [--sources wit.sources.json --allow-exec] [--env .env]
wit tour <file> [--report | --no-report]
wit tokens [--parser] <file> | -e <source>
wit migrate <file|dir>… [-w|--write]
wit --version | --help
Exit codes
ExitMeaning
0success
1a stage or file error
2bad usage — an unknown command or flag or a missing file

wit build

The full pipeline: parse → load → resolve → expand → render. Definitions in every referenced file are scanned first, so a use of a definition from another file needs no close there either.

build flags
FlagMeaningDefault
-o or --out PATHwrite to a file; format from the extensionstdout
--format html|md|pdfset the format explicitlyhtml
--fragmentonly the article elementoff
--rawfull page with a reset-only stylesheetoff
--template NAMEbuild with a bundled template instead of the one referencednone
--paper a4|a5|letter|legalpage size; beats the template'sthe template's
--sources FILEexternal-data source confignone
--env FILEdotenv merged into the env source and child processesnone
--allow-execallow running configured source programsoff
Format from the extension
ExtensionFormat
.html or .htmhtml
.md or .markdownmd
.pdfpdf
anything elseE_UNKNOWN_OUTPUT_FORMAT — exit 1
  • Default HTML is a self-contained page with the bundled theme. With both --fragment and --raw, --fragment wins.
  • Relative asset paths (src, href) in a referenced file are rebased to the file you build, when the asset lives beside the referenced file.
  • PDF needs -o file.pdf and a system Chrome or Chromium (WIT_CHROME overrides the search, with no fallback). Wit writes a temporary HTML with a <base href> so assets resolve, prints with a 60-second timeout, and fails — rather than leave a stale PDF — if no PDF is written.

wit check

Runs the same pipeline as build without rendering — a faithful dry run, including @load when given the same data flags. Takes several files and reports the first error in each.

check
OutcomeOutputExit
all cleanok: FILE per file0
any file failsthe diagnostic on stderr1
no file or unknown flagusage on stderr2

wit fmt

Re-indents a file to match its nesting without changing what it renders. Prose, raw bodies, scripts and data values stay as written. One file at a time.

fmt
FlagEffectExit
noneformatted source to stdout0
-w or --writewrite in place; prints formatted FILE or unchanged FILE0
--checkwrite nothing; exit 1 and name the file if it would change0 or 1
parse errornothing written1

wit migrate

Rewrites Wit 0.2 syntax as 0.3 — pipes, capture lists, { … } calls, space-separated params, colon-scatter, form-fill uses, ..., key - value and equals. Directories are searched for .wit files (skipping node_modules, dist and dot-folders). Each file is migrated against the definitions in it and every file it references.

migrate
CallEffect
one fileprint the migrated source
several files or a directorylist each FILE: needs migrating
-w or --writerewrite changed files in place
a construct it cannot rewriteFILE:LINE:COL: warning: … on stderr

Exit 1 if any file fails to read or lex; 2 with no path.

wit migrate chapters/ -w
wit check chapters/*.wit

wit parse

Prints the AST as JSON. Exactly one file, no flags. See AST reference.

wit tokens

Prints the token stream, one token per line: position, kind, payload, source text. --parser shows the stream the parser walks, after stray markers are turned back into prose. -e takes source inline; \n in it is a newline. Use it to see why a piece of prose became structure, or did not.

wit tokens --parser -e 'See (a(href: /x) the site a) and (a few notes).'

wit tour

An indented AST tree plus a coverage footer: AST kinds seen out of 24, the paramsSource variants (parens, none) and the definition shapes. The footer shows on a TTY; --report / --no-report force it on or off.

Environment

Environment variables
VariableEffect
WIT_CHROMEbrowser for PDF output — no fallback
WIT_DEBUG_COMMENTS=1keep comments in HTML output
WIT_TOUR_REPORT=1 / WIT_TOUR_NO_REPORT=1force the tour footer on or off

See also

Config · Errors · API · CLI guide.