An MkDocs plugin to generate documentation for a rich argparse parser. It renders commands, sub commands and sub-sub commands which can have rich help messages.
pip install mkdocs-rich-argparseTL;DR: Set package to your installed CLI package's project name and add
cli.md to your navigation.
-
Define your commands in your package's
pyproject.tomlusing[project.scripts]:[project] name = "my-package" [project.scripts] myprogram = "my_package.cli:main" mysecondprogram = "my_package.cli:download"
-
Ensure your CLI package is installed alongside the plugin so its script metadata is available.
-
In
mkdocs.yml, setpackageto the[project].namevalue from yourpyproject.tomland add the generated page to your navigation:plugins: - mkdocs-rich-argparse: package: my-package nav: - CLI Reference: cli.md
Parsers are captured at parse_args() or parse_known_args(). Code before
parsing still executes during the documentation build.
See the example/ directory for a minimal example and a custom styled example.
package is required. All other plugin settings are optional and belong under
mkdocs-rich-argparse in mkdocs.yml:
| Setting | Default | Description |
|---|---|---|
src_uri |
cli.md |
Generated page path relative to the docs directory. Update nav to match. |
heading |
CLI Reference |
Top-level heading of the generated page. |
order |
[] |
Script names to document first, in the specified order. |
styles |
See below | Rich styles for the generated help text. |
For example, customize the page path and heading and put your main script first:
plugins:
- mkdocs-rich-argparse:
package: my-package
src_uri: reference/commands.md
heading: Commands
order:
- myprogram
nav:
- Commands: reference/commands.mdScripts listed in order appear first, in the specified order.
All remaining scripts are sorted alphabetically.
Unknown or duplicate script names cause a build error.
If no order is specified, all scripts are sorted alphabetically.
The styles mapping accepts Rich style strings for args, groups, help,
metavar, syntax, text, and default. The plugin sets help and text to
green by default so they remain visible in dark mode. Other values keep the
current RichHelpFormatter styles unless overridden.
plugins:
- mkdocs-rich-argparse:
package: my-package
styles:
args: bright_red
groups: bright_green
metavar: bright_magenta
syntax: dark_orange
help: bright_cyan
text: bright_yellow
default: bright_blackTo preserve Rich colors in CI, set these environment variables (GitHub Actions example):
env:
TTY_COMPATIBLE: '1'
TTY_INTERACTIVE: '0'If you want to contribute to the development of mkdocs_rich_argparse, have a look at the contribution guidelines.
