MkDocs-Click
MkDocs-Click is an MkDocs extension designed to automatically generate comprehensive documentation for Click command-line applications. It parses Click command structures and renders them directly into MkDocs pages, including options, arguments, and subcommands. The current version is 0.9.0, and it maintains an active release cadence, adapting to changes in both MkDocs and Click.
Warnings
- breaking Support for Python 3.8 has been dropped in version 0.9.0. Users on Python 3.8 or older must upgrade their Python environment or use mkdocs-click version 0.8.x or earlier.
- breaking Due to upstream breaking changes in Click, mkdocs-click versions may have specific compatibility ranges. Version 0.6.0 explicitly adjusted to a breaking change in Click. Ensure your Click version is compatible with your mkdocs-click version (currently Click `>=7,<9`).
- gotcha The behavior of `--help` options changed in version 0.3.0. Previously, `--help` was automatically dropped from the generated documentation; it is now kept in options by default. This might change the rendered output for older configurations.
- gotcha In versions prior to 0.8.1, the `:::{.mkdocs-click}` directive required an extra newline at the end of the file or before subsequent content to be properly parsed. This could lead to content not being rendered.
Install
-
pip install mkdocs-click
Imports
- ClickExtension
from mkdocs_click.extension import ClickExtension
Quickstart
mkdocs new my-click-docs
cd my-click-docs
pip install mkdocs mkdocs-click click
# --- my_cli.py ---
import click
@click.group()
def cli():
"""My super CLI tool."""
pass
@cli.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.argument('name')
def hello(count, name):
"""Greets the NAME for a COUNT times."""
for x in range(count):
click.echo(f"Hello {name}!")
# --- mkdocs.yml ---
site_name: My Click Documentation
extensions:
- mkdocs-click
# --- docs/index.md ---
# My Click Application Documentation
```python
# my_cli.py
import click
@click.group()
def cli():
"""My super CLI tool."""
pass
@cli.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.argument('name')
def hello(count, name):
"""Greets the NAME for a COUNT times."""
for x in range(count):
click.echo(f"Hello {name}!")
```
:::{.mkdocs-click}
#:
:module: my_cli
:command: cli
:::
# Building and serving
mkdocs build
mkdocs serve