Run commands against code blocks in reStructuredText and Markdown files.
Project description
doccmd
A command line tool for running commands against documentation files.
Installation
With pip
Requires Python 3.11+.
pip install doccmd
With Homebrew (macOS, Linux, WSL)
Requires Homebrew.
brew tap adamtheturtle/doccmd
brew install doccmd
Pre-built Linux binaries
$ curl --fail -L https://github.com/adamtheturtle/doccmd/releases/download/2024.09.14.2/doccmd -o /usr/local/bin/doccmd && \
$ chmod +x /usr/local/bin/doccmd
Using doccmd as a pre-commit hook
To run doccmd with pre-commit, add hooks like the following to your .pre-commit-config.yaml:
- repo: https://github.com/adamtheturtle/doccmd-pre-commit
rev: v2024.09.14.2
hooks:
- id: doccmd
args: ["--language", "shell", "--command", "shellcheck --shell=bash"]
additional_dependencies: ["shellcheck-py"]
Usage example
# Run mypy against the Python code blocks in README.md and CHANGELOG.rst
$ doccmd --language=python --command="mypy" README.md CHANGELOG.rst
# Run gofmt against the Go code blocks in README.md
# This will modify the README.md file in place
$ doccmd --language=go --command="gofmt -w" README.md
# or type less...
$ doccmd -l python -c mypy README.md CHANGELOG.rst
What does it work on?
reStructuredText (.rst)
.. code-block:: shell
echo "Hello, world!"
.. code:: shell
echo "Or this Hello, world!"
Markdown (.md)
```shell
echo "Hello, world!"
```
MyST (.md with MyST syntax)
```{code-block} shell
echo "Hello, world!"
```
```{code} shell
echo "Or this Hello, world!"
```
Want more? Open an issue!
Formatters and padding
Running linters with doccmd gives you errors and warnings with line numbers that match the documentation file. It does this by adding padding to the code blocks before running the command.
Some tools do not work well with this padding, and you can choose to obscure the line numbers in order to give the tool the original code block’s content without padding, by using the --no-pad-file flag.
Full documentation
See the full documentation.
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
Hashes for doccmd-2024.9.14.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a9629e535e4792c06fac14df04c01cb4e5da8ca39377086dc07ca40394a954a |
|
MD5 | 5748abc61633816d4de1e300d0ff442a |
|
BLAKE2b-256 | f31991e78f03c59832e76af95d1552c3ba5f6f9e58142f1371536320fc4c03d9 |