An MkDocs extension to generate documentation for Click command line applications
Project description
mkdocs-click
An MkDocs extension to generate documentation for Click command line applications.
Installation
Install from PyPI:
pip install mkdocs-click
Quickstart
Add mkdocs-click
to Markdown extensions in your mkdocs.yml
configuration:
site_name: Example
theme: readthedocs
markdown_extensions:
- mkdocs-click
Add a CLI application, e.g.:
# app/cli.py
import click
@click.group()
def cli():
"""Main entrypoint."""
@cli.command()
@click.option("-d", "--debug", help="Include debug output.")
def build(debug):
"""Build production assets."""
Add a mkdocs-click
block in your Markdown:
# CLI Reference
This page provides documentation for our command line tools.
::: mkdocs-click
:module: app.cli
:command: cli
Start the docs server:
mkdocs serve
Tada! 💫
Usage
Documenting commands
To add documentation for a command, add a mkdocs-click
block where the documentation should be inserted.
Example:
::: mkdocs-click
:module: app.cli
:command: main
For all available options, see the Block syntax.
Multi-command support
When pointed at a group (or any other multi-command), mkdocs-click
will also generate documentation for sub-commands.
This allows you to generate documentation for an entire CLI application by pointing mkdocs-click
at the root command.
Tweaking header levels
By default, mkdocs-click
generates Markdown headers starting at <h1>
for the root command section. This is generally what you want when the documentation should fill the entire page.
If you are inserting documentation within other Markdown content, you can set the :depth:
option to tweak the initial header level. Note that this applies even if you are just adding a heading.
By default it is set to 0
, i.e. headers start at <h1>
. If set to 1
, headers will start at <h2>
, and so on. Note that if you insert your own first level heading and leave depth at its default value of 0, the page will have multiple <h1>
tags, which is not compatible with themes that generate page-internal menus such as the ReadTheDocs and mkdocs-material themes.
Full command path headers
By default, mkdocs-click
outputs headers that contain the command name. For nested commands such as $ cli build all
, this also means the heading would be ## all
. This might be surprising, and may be harder to navigate at a glance for highly nested CLI apps.
If you'd like to show the full command path instead, turn on the Attribute Lists extension:
# mkdocs.yaml
markdown_extensions:
- attr_list
- mkdocs-click
mkdocs-click
will then output the full command path in headers (e.g. ## cli build all
) and permalinks (e.g. #cli-build-all
).
Note that the table of content (TOC) will still use the command name: the TOC is naturally hierarchal, so full command paths would be redundant. (This exception is why the attr_list
extension is required.)
Reference
Block syntax
The syntax for mkdocs-click
blocks is the following:
::: mkdocs-click
:module: <MODULE>
:command: <COMMAND>
:prog_name: <PROG_NAME>
:depth: <DEPTH>
:style: <STYLE>
Options:
module
: Path to the module where the command object is located.command
: Name of the command object.prog_name
: (Optional, default: same ascommand
) The name to display for the command.depth
: (Optional, default:0
) Offset to add when generating headers.style
: (Optional, default:plain
) Style for the options section. The possible choices areplain
andtable
.
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog.
0.4.0 - 2021-05-12
Added
- Relax
click
version constraint. (Pull #39)
0.3.0 - 2021-02-19
Changed
--help
is now kept in options (it used to be automatically dropped). (Pull #29)
Added
- Add table formatting. (Pulls #25, #30)
- Use
:prog_name:
more consistently in usage. (Pull #24) - Allow using full command paths in headers. (Pull #36)
Fixed
- Make usage and options headings bold to improve legibility. (Pull #31)
0.2.0 - 2020-12-09
Added
- Add
:prog_name:
option to allow overriding the name of the CLI program. (Pull #8, contributed by @frankier.) - Add official support for Python 3.9. (Pull #20)
Fixed
- Properly pin
click==7.*
andmarkdown==3.*
. (Pull #19)
0.1.1 - 2020-06-05
Fixed
- Raise proper error when processing unnamed commands. (Pull #4)
0.1.0 - 2020-06-04
Initial implementation.
Added
- Add
::: mkdocs-click
block with:module:
,:command:
and:depth:
options.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mkdocs_click-0.4.0.tar.gz
.
File metadata
- Download URL: mkdocs_click-0.4.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b34be84cde57850733fb1b32db37b472620ac2c3e97db4abbe11dbd6b98124f2 |
|
MD5 | d2a551f285bbb1460133c03b0f712733 |
|
BLAKE2b-256 | 1b94912d45ec22d56d811bf90c60c5d8636b8243026658b2a0eedfc3bc523cd6 |
Provenance
File details
Details for the file mkdocs_click-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: mkdocs_click-0.4.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b54c65bd1e6e2b600da71d77705e911d15d86bc2c2b341ff5d7f76b9fe1505b |
|
MD5 | 19eb31e880c840bc6b828043a5030d00 |
|
BLAKE2b-256 | df9a052f01621da27999724a361806adb66a5fae60fa435f812f43cab8704815 |