clap-markdown-generator
Generate Markdown documentation from clap command definitions.
clap-markdown-generator is useful when a CLI parser is already the source of truth and you want reference documentation for every available parameter without maintaining a second hand-written list. The generated Markdown includes anchors, descriptions, default values, environment variables, possible values, required/value metadata, and recursive subcommand sections.
Installation
[]
= "0.1"
Your CLI type should use clap as usual:
[]
= { = "4.5", = ["derive", "env"] }
= "0.1"
Usage
use ;
The output contains stable HTML anchors for each parameter. The parameter list uses only the first line of each parameter description as its summary, while the detailed parameter section keeps the full description.
Example command line interface
- -
<a id="example-config"></a>
Path to the configuration file
<a id="example-network"></a>
Network to connect to
<a id="example-daemon"></a>
-
Start the daemon
-
<a id="example-daemon-rpc-bind"></a>
RPC bind address
API
Use generate_markdown::<T>() for a type that derives clap::Parser or otherwise implements clap::CommandFactory.
let markdown = ;
Use generate_markdown_for_command when you already have a clap::Command.
let command = command;
let markdown = generate_markdown_for_command;
Use generate_markdown_for_command_with_options to customize rendering.
use ;
let markdown = generate_markdown_for_command_with_options;
Rendering Options
| Option | Default | Description |
|---|---|---|
include_hidden |
false |
Include clap arguments and subcommands marked as hidden. |
include_subcommands |
true |
Recursively document subcommands. |
include_toc |
true |
Include the parameter summary section. |
skip_parameter_details |
false |
Skip the detailed parameter sections like ### --config <CONFIG>. |
include_html_anchors |
true |
Include explicit HTML anchor id elements like <a id="example-config"></a>. |
include_usage |
true |
Include usage content like Usage: --config <CONFIG> in detailed parameter sections. |
command_heading |
Display |
Render command headings with the default full command path, skip them, or use a callback. |
summary |
names + values + descriptions | Configure whether the parameter summary is enabled, whether it shows only names or names plus values, whether it includes the first description line, or use a callback for each entry. |
parameter_heading |
Display |
Render detailed parameter headings as the full display form, the clap argument name, or a callback. |
parameter_content |
Table |
Render detailed parameter metadata as a table, compact text, or a callback. |
Summary Style
The summary can be disabled entirely or reduced to just names:
MarkdownOptions
This changes summary entries from:
-
to:
-
Detail Style
Detailed parameter sections can be skipped:
MarkdownOptions
Explicit HTML anchor id elements can be hidden while keeping generated anchor names available for links and metadata:
MarkdownOptions
Command headings can be customized or skipped:
MarkdownOptions
Use CommandHeadingStyle::None to omit command headings. A custom callback can also return an empty string to skip a specific heading.
Summary entries can use a callback for complete control over each list item:
MarkdownOptions
Parameter headings can use the full display form, only the clap argument name, or a callback:
MarkdownOptions
MarkdownOptions
Parameter content can use compact text instead of a table:
MarkdownOptions
Or provide your own callback:
MarkdownOptions
clap-markdown-generator filters clap-generated help and version actions from the output so the documentation focuses on user-defined CLI parameters.
Development