CLI reference
Generate the reference pages of a command line from its usage spec, so the commands, flags and defaults on your site cannot drift from the tool.
A CLI reference lists every command, argument and flag of a command line tool with its defaults, choices and environment variables. Written by hand it goes stale with the first release that adds a flag. integrations.cli generates it instead: your tool writes a spec of its own interface, and Publier turns that spec into pages on every build. The prose around the reference (when to use which command, worked scenarios) stays a hand-written guide. integrations.openapi does the same for an HTTP API.
Quickstart
-
Produce a usage spec from your tool. Publier reads the usage KDL spec format, which many command line frameworks can export; see Producing the spec. A spec looks like this:
reference/mycli.usage.kdl bin "mycli"version "1.4.0"about "Deploys services."flag "-v --verbose" help="Print more output" global=#truecmd "login" help="Sign in" {flag "--token <token>" help="API token" env="MYCLI_TOKEN"}cmd "config" help="Read and write settings" {cmd "get" help="Print one setting" {arg "<key>"}} -
Declare it in
publier.config.yaml:publier.config.yaml integrations:cli:- format: usagesource: ./reference/mycli.usage.kdlpath: /docs/cliformatisusage, the only format today.sourceis a project-relative path or anhttps://URL; a URL is fetched on every build and its redirects are followed, so the download link of a release asset works.pathis the route the pages live under. It must sit below/docsand cannot share a path with, or nest inside, another generated path of any kind (anintegrations.openapientry included). List several entries for several tools. -
Run
publier devorpublier build. Publier reads the spec and writes the pages intosrc/content/docs/<path>.
What it generates
| Page | File below the folder | Holds |
|---|---|---|
| Root | index.mdx | The CLI’s name and version, the synopsis, the global options and a table of the commands, each linked to its page |
| A command | login.mdx, or config/get.mdx when nested | The command’s description, its usage line, its arguments and options, its subcommands and examples |
| A command with subcommands | config/index.mdx | The same, and the folder config/ holds its subcommands |
The URL does not depend on which of the two forms a command takes: config is at /docs/cli/config, config get at /docs/cli/config/get. A meta.yaml in each folder puts the pages in the order of the spec in the sidebar.
A command page has these sections, each present only when the command has something to put in it:
- Overview: the description, a deprecation notice, and the aliases.
- Usage: the synopsis in a code block, for example
mycli login --token <token> [OPTIONS]. Required flags are spelled out; the others are folded into[OPTIONS]. - Arguments and Options: Markdown tables with the name, the description, and, when any row has one, the default, the choices, the environment variable and whether the argument or flag is required. A flag that is deprecated, repeatable or global says so in its description. Options inherited from a parent command’s global flags are listed by name with a link to where they are described.
- Subcommands, Examples.
Hidden commands, flags and arguments are left out. The pages are ordinary Markdown headings and tables, so the table of contents, search and llms.txt see every flag.
Each section heading carries a stable id made from the command path, so a link keeps working when the wording of a heading changes: /docs/cli/login#mycli-login-options. The id of a command is its path joined with - (mycli-login, mycli-config-get); a section adds its name (-usage, -arguments, -options, -subcommands, -examples). On the root page the sections are mycli-usage, mycli-global-options and mycli-commands.
Text from the spec is shown as text. Braces, tags, import lines and $ in a description render literally and are never read as MDX, HTML or math, so a description such as {count} <items> appears as written. A spec that does not parse fails the build with the source and the line and message of the parser. A spec that pulls in other files with include is refused: give Publier one self-contained spec.
Producing the spec
The release of your tool should produce the spec, and the docs build should only read it. That keeps a language toolchain out of the docs build, and the reference matches the version you released.
- clap (Rust). The
clap_usagecrate, described in the usage documentation, generates a spec from aclap::Command. Theusage-libcrate does the same through itsclapfeature: withusage-lib = { version = "7", default-features = false, features = ["clap"] },usage::Spec::from(&Cli::command()).to_string()is the KDL text (Cli::command()comes fromclap::CommandFactory). A hidden subcommand that prints it, run in your release job, gives you a file to publish with the release. - Other frameworks. The usage project lists exporters for Cobra, Kong and urfave/cli (Go), Click, Typer and argparse (Python), oclif, yargs and Commander.js (Node.js), Effect (TypeScript), OptionParser (Ruby), and JCommander and picocli (Java), among others, at usage.jdx.dev/spec/integrations (checked 2026-11-16). Each exporter covers a different subset of its framework’s features, so read its notes on what it cannot express before you rely on it.
- By hand. The spec is a text file in a documented grammar, usage.jdx.dev/spec. A hand-written spec works, and loses the point of generating the reference from the tool.
Pin the spec to the release it describes: commit it next to your docs, or point source at the release asset’s URL. To document several releases, give each its own entry and path and list them under the product’s versions, as the versioning guide does for hand-written pages.
To show what changed between releases, list the earlier specs under history and Publier badges each command and flag with “Added in”, “Changed in” or “Deprecated in”. The release history badges section of the SDK reference guide describes the options and the rules, which are the same for integrations.cli.
The generated folder
Publier owns the folder a path maps to. It deletes and rewrites it on every build, and it writes a .gitignore containing * into it, so the pages are never committed. The build fails, naming the files, if the folder contains a file Publier did not generate, so keep hand-written pages (the introduction to the CLI, a getting-started guide) outside it, next to the folder rather than in it. In publier dev, a change to a local spec regenerates the pages. A spec fetched from a URL is read again on the next build or dev start.
Product, version and version status come from your navigation by path prefix, as for a hand-written page at that path.