Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ comline-core = { git = "https://github.com/ComlineProject/core", rev = "52593935
# `comline-codegen`'s types, so the rev below must be byte-identical to the
# one *they* pin - Cargo only unifies a git dependency across identical rev
# strings, and two copies of `GenRequest` are two incompatible types.
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "ac4425c32f88f98a2a3bfb971a209c173c6559a8" }
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "6889d3db79ab20f7091d309071ea0b41e2ed5317" }
# The official Markdown and HTML documentation renderers (`comline doc`),
# linked in like the official generators. Same generation rev as
# `comline-codegen`.
comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "ac4425c32f88f98a2a3bfb971a209c173c6559a8" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "ac4425c32f88f98a2a3bfb971a209c173c6559a8" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "8d0d659d100d41d64d203a7890a6b15471cde802", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "37cd70f96260325f37a39be6a15cb858d2e069dc", optional = true }
comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "6889d3db79ab20f7091d309071ea0b41e2ed5317" }
comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "6889d3db79ab20f7091d309071ea0b41e2ed5317" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "0e39319a80be086f6dbee1a3a017eab0662925b6", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "ad8756847518e6af281c46d1d0e441fdb46e9dde", optional = true }
# `comline conformance`: the conformance runner (corpus loading, judging,
# profile proofs) and its case format, a public spec. Pinned by git rev.
comline-runtime-conformance = { git = "https://github.com/ComlineProject/runtime", rev = "4378c91b74ee1ef1debc800a3daf75c874198e70" }
Expand Down
94 changes: 66 additions & 28 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,62 +449,100 @@ argument matches no stored version (the error lists the versions that exist).
### `comline doc`

```
comline doc [--out <dir>] [--version <v>] [--changelog-from <v>] [--format markdown|html|json]
comline doc [--out <dir>] [--version <v>] [--changelog-from <v>] [--format <f>[,<f>...]]
```

Write the package's documentation. Nothing is written to `.comline/`.
Write the package's documentation for every version: each release, each dev
build and the unreleased working state (when it differs from the last build).
Nothing is written to `.comline/`.

Each format lands in `<out>/<format>/`, with one folder per version:
`0.2.0/`, `0.3.0-dev.2/`, and `unreleased/` for the working tree. Each
version carries the changelog from the version before it, computed by core's
`comline diff` rules.

- **Pages** (`markdown`, the default, rendered by the official renderer linked
into `comline`): `index.md` (the package, its `//!` header, its modules), one
page per module (`types::user` is `types/user.md`) with its `//!` header and
every unit with its `///` docs, fields, arguments and each protocol's wire
summary, `changelog.md` with `--changelog-from`, and `nav.yml`, a `nav` for
mkdocs or zensical.
- **`html`** writes a self-contained static site, rendered by the official HTML
renderer, also linked in: `index.html`, one page per module
(`types/user.html`), `changelog.html` with `--changelog-from`, `style.css`
and `search.js`. It has the same content as the Markdown pages, plus a
sidebar of modules and units, a search box over the units (the index is
inlined in `search.js`), and light and dark themes that follow the OS
setting. Nothing loads from the network and every link is relative, so
`index.html` opens straight from disk or from any static host.
- **`json`** writes the documentation model itself, `model.json`, in the shape
of core's `schemas/doc-model.json`.
into `comline`): per version, `index.md` (the package, its `//!` header, its
modules), one page per module (`types::user` is `types/user.md`) with its
`//!` header and every unit with its `///` docs, fields, arguments and each
protocol's wire summary, `changelog.md`, and `nav.yml`, a `nav` for mkdocs
or zensical. `<out>/markdown/index.md` lists the versions. Switching
versions on a published site is left to site tooling, such as
[mike](https://github.com/jimporter/mike) for mkdocs.
- **`html`** writes a self-contained static site per version, rendered by the
official HTML renderer, also linked in: `index.html`, one page per module
(`types/user.html`), `changelog.html`, `style.css` and `search.js`. It has
the same content as the Markdown pages, plus a sidebar of modules and units,
a search box over the units, a version picker in the header, and light and
dark themes that follow the OS setting. The picker opens the same page and
unit in the chosen version, or that version's index with a note when it has
no such page. At `<out>/html/`, `index.html` points at the latest version
(the newest release, else the newest dev build), and `compare.html`
compares versions: two show what changed between them, grouped by unit and
labelled major, minor or patch; more show a grid of every unit and member
per version. The labels come from the changelogs core computed between each
version and the one before it; the page never judges a change itself.
Nothing loads from the network and every link is relative, so the site opens
straight from disk or from any static host.
- **`json`** writes each version's documentation model, `model.json`, in the
shape of core's `schemas/doc-model.json`, and `<out>/json/index.json`
listing the versions.

| Flag | Default | Meaning |
|---|---|---|
| `--out <dir>` | `[doc] out`, else `docs/api` | where to write, relative to the project |
| `--version <v>` | the working tree | document a built version (a version string, a commit hash, or `HEAD`) from its frozen IR, `//!` headers included |
| `--changelog-from <v>` | `[doc] changelog_from` | add what changed from built version `<v>` to the documented one |
| `--format <f>` | `[doc] format`, else `markdown` | `markdown`, `html`, `json`, or another id the `[doc] renderer` offers |

A built version keeps no source, so with `--version` its protocols have no wire
summary. A version built before headers were stored has none.
| `--version <v>` | every version | document only this built version (a version string, a commit hash, or `HEAD`), into `<out>/<format>/<v>/` |
| `--changelog-from <v>` | `[doc] changelog_from` | with `--version`: add what changed from built version `<v>` |
| `--format <f>` | `[doc] formats`, else `markdown` | `markdown`, `html`, `json`, or another id the `[doc] renderer` offers; repeat it or separate with commas |

**Caching.** A built version never changes, so its folder is kept between
runs. `<out>/<format>/.comline-doc.json` records the key each folder was
rendered with: its commit, the commit of the version before it, the renderer
and its version, the model version and the links. A built-in renderer's
version carries a content hash of its sources and assets (`0.1.0+<hash>`),
so a `comline` with a changed renderer re-renders every folder; an external
renderer is keyed by its file's hash. A run re-renders only the
folders whose key changed, which is the unreleased state and new versions,
and removes the folders of versions no longer listed.

A built version keeps no source, so its protocols have no wire summary, and a
version built before headers were stored has no `//!` headers. Its pages say
so in a note.

`comline.toml`'s `[doc]` table:

```toml
[doc]
out = "docs/api"
format = "markdown"
formats = ["html", "markdown", "json"]
versions = { last = 5 } # or "all" (the default), { since = "0.3.0" }, { releases_only = true }
renderer = "renderers/my-renderer.wasm" # optional: an external renderer
timeout = 60 # seconds per call to `renderer`
links = { std = "https://comlineproject.github.io/docs/std/" }
changelog_from = "0.1.0"
changelog_from = "0.1.0" # with --version only
```

- `versions` trims the list. `last = N` keeps the newest N (the unreleased
state counts as one), `since` keeps that version and newer, and
`releases_only` keeps releases alone (no dev builds and no unreleased
state). They combine, applied in that reverse order: `releases_only`, then
`since`, then `last`.
- `renderer` is run exactly like an external `generator`: a `.wasm` under
wasmtime with no filesystem, environment or network, a native executable with
an empty environment, the same limits and path checks. It must list the
format in its `Describe` answer's `renderers`.
format in its `Describe` answer's `renderers`. One that doesn't render a
site index (`sites` in its `Describe` answer) still renders every version's
folder.
- `links` maps a dependency (or `std`) to the base URL of its documentation. A
type from it links to `<base>/<module>/#<anchor>`; a dependency not listed is
plain text.

`comline new` adds `docs/api/html/` to `.gitignore`.

```bash
comline doc
comline doc --out site/api --changelog-from 0.1.0
comline doc --version 0.2.0
comline doc --format html,markdown
comline doc --version 0.2.0 --changelog-from 0.1.0
comline doc --format html --out site
comline doc --format json
```
Expand Down
58 changes: 35 additions & 23 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,46 +102,58 @@ Examples:

/// Write the package's documentation: Markdown pages, or the model as JSON
#[command(long_about = "\
Write the package's documentation: an index page, one page per module (its \
`//!` header, every unit with its `///` docs, fields, arguments and each \
protocol's wire summary), a changelog page with `--changelog-from`, and an \
mkdocs/zensical `nav.yml`. Read-only: nothing is written to `.comline/`.

The working tree is documented unless `--version` names a built version (a \
version string, a commit hash or `HEAD`), which is documented from its frozen \
IR, `//!` headers included. A built version keeps no source, so its protocols \
have no wire summary.

`--format html` writes a self-contained static site instead: `index.html`, \
one page per module, `changelog.html`, a stylesheet and a search script, all \
linked relatively, so `index.html` opens straight from disk. `--format json` \
writes the documentation model itself (`model.json`), for other tools. `comline.toml`'s `[doc]` table sets the defaults: `out` \
(`docs/api`), `format` (`markdown`), `renderer` (an external renderer, run \
like an external generator), `links` (dependency docs URLs) and \
Write the package's documentation for every version: each release, each dev \
build and the unreleased working state (when it differs from the last build), \
each into `<out>/<format>/<version>/` (`unreleased/` for the working tree) with \
the changelog from the version before it. Per version: an index page, one page \
per module (its `//!` header, every unit with its `///` docs, fields, arguments \
and each protocol's wire summary) and a changelog page. Read-only: nothing is \
written to `.comline/`.

`markdown` (the default) writes pages and an mkdocs/zensical `nav.yml` per \
version, plus an `index.md` listing the versions. `html` writes a \
self-contained static site per version, with a version picker in its header, \
and at `<out>/html/` an `index.html` pointing at the latest version and a \
`compare.html` to compare versions; everything links relatively and opens \
straight from disk. `json` writes each version's documentation model \
(`model.json`) and an `index.json`.

A built version's folder is kept between runs while nothing it was rendered \
from changes (`<out>/<format>/.comline-doc.json` records why), so a run \
re-renders only the unreleased state and new versions. `--version` documents \
one built version alone (a version string, a commit hash or `HEAD`), and \
`--changelog-from` then adds a changelog from an earlier one. A built version \
keeps no source, so its protocols have no wire summary, and one built before \
headers were frozen has no `//!` headers; its pages say so.

`comline.toml`'s `[doc]` table sets the defaults: `out` (`docs/api`), \
`formats` (`[\"markdown\"]`), `versions` (`\"all\"`, or `{ last = N }`, \
`{ since = \"0.3.0\" }`, `{ releases_only = true }`), `renderer` (an external \
renderer, run like an external generator), `links` (dependency docs URLs) and \
`changelog_from`.

Examples:
comline doc
comline doc --out site/api --changelog-from 0.1.0
comline doc --version 0.2.0
comline doc --format html,markdown
comline doc --version 0.2.0 --changelog-from 0.1.0
comline doc --format html --out site
comline doc --format json")]
Doc {
/// Output directory; default from `[doc] out`, else `docs/api`
#[arg(long, value_name = "DIR")]
out: Option<std::path::PathBuf>,

/// Document this built version instead of the working tree
/// Document only this built version, into `<out>/<format>/<VERSION>/`
#[arg(long = "version", value_name = "VERSION")]
doc_version: Option<String>,

/// Add a changelog from this built version to the documented one
/// With `--version`: add a changelog from this built version
#[arg(long, value_name = "VERSION")]
changelog_from: Option<String>,

/// `markdown` (pages), `html` (a static site) or `json` (the model); default from `[doc] format`
#[arg(long, value_name = "FORMAT")]
format: Option<String>,
/// `markdown` (pages), `html` (a static site) or `json` (the model), repeatable or comma-separated; default from `[doc] formats`
#[arg(long = "format", value_name = "FORMAT", value_delimiter = ',')]
format: Vec<String>,
},

/// Validate the project and write generated code for each configured target
Expand Down
Loading
Loading