Skip to content

Commit d7c72cc

Browse files
authored
Docs/update readme (#13)
## Overview This PR adds support for configuring the `pretty` option at the individual documentation block level, allowing users to override the global setting on a case-by-case basis. It also includes updates to the project version (0.1.4) and comprehensive documentation of changes in the CHANGELOG. ## Changes - Added version 0.1.4 to the CHANGELOG with detailed entries - Enhanced the `TyperProcessor.run()` method to support per-block configuration for the `pretty` option - Improved boolean parsing for the pretty option to properly handle string values like "true", "false", "1", "0", etc. - Added comprehensive tests with parameterized test cases to verify all combinations of global and block-level settings - Updated documentation to reflect new capabilities ## Implementation Details The implementation properly prioritizes block-level settings over global settings: - The global setting is used as the default - If a block includes a `:pretty:` directive, it overrides the global setting - The block-level setting properly handles different boolean-like string values ## Testing - Added a new parameterized test case `test_typer_processor_pretty_option` to verify all combinations of global and block-level pretty settings - All 26 tests are now passing with 97% coverage - Manually verified the functionality by running the MkDocs server and checking the documentation output ## Other Notes The changes are backward compatible with existing documentation and do not affect previous functionality. Users can continue using the global setting or now opt to override it in specific documentation blocks as needed.
1 parent 38bd12b commit d7c72cc

File tree

11 files changed

+186
-21
lines changed

11 files changed

+186
-21
lines changed

.coverage

0 Bytes
Binary file not shown.

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12
1+
3.13

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [unreleased]
9+
10+
## [0.1.4] - 2025-03-15
11+
12+
### Added
13+
- Added support for Python 3.13
14+
- Added per-block configuration for `pretty` option in documentation directives
15+
- Added justfile for common development tasks
16+
- Added docs/cli-pretty.md example for pretty-formatted CLI documentation
17+
- Added docs/changelog.md that includes the project's CHANGELOG
18+
19+
### Changed
20+
- Enhanced documentation with more detailed usage instructions and examples
21+
- Updated navigation structure in mkdocs.yaml
22+
- Improved TyperProcessor to support overriding global `pretty` setting at the block level
23+
24+
## [0.1.3] - 2025-03-09
925

1026
### Fixed
1127
- Fixed issue where docstrings weren't displayed in the generated documentation when `pretty` option was enabled

README.md

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# mkdocs-typer2
22

33
[![PyPI version](https://badge.fury.io/py/mkdocs-typer2.svg)](https://badge.fury.io/py/mkdocs-typer2)
4-
![Python 3.10 | 3.11 | 3.12](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12-blue.svg)
4+
![Python 3.10 | 3.11 | 3.12 | 3.13](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12-blue.svg)
55
![Ruff](https://img.shields.io/badge/linted%20by-ruff-FFC107.svg)
66
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
77
[![Downloads](https://static.pepy.tech/badge/mkdocs-typer2)](https://pepy.tech/project/mkdocs-typer2)
88
[![codecov](https://codecov.io/gh/syn54x/mkdocs-typer2/branch/main/graph/badge.svg)](https://codecov.io/gh/syn54x/mkdocs-typer2)
99
[![Issues](https://img.shields.io/github/issues/syn54x/mkdocs-typer2)](https://github.com/syn54x/mkdocs-typer2/issues)
1010

11-
12-
1311
A MkDocs plugin that automatically generates beautiful documentation for your Typer CLI applications.
1412

15-
You might be wondering why there are two plugins for Typer. The [`mkdocs-typer`](https://github.com/bruce-szalwinski/mkdocs-typer) plugin is great, but it hasn't been updated in over a year, and there have been a number of changes to Typer since then. One important change is that Typer now has it's own documentation generation system via the `typer <module> utils docs` command. This plugin simply leverages that system to generate the documentation for your Typer CLIs.
13+
You might be wondering why there are two plugins for Typer. The [`mkdocs-typer`](https://github.com/bruce-szalwinski/mkdocs-typer) plugin is great, but it hasn't been updated in over a year, and there have been a number of changes to Typer since then. One important change is that Typer now has its own documentation generation system via the `typer <module> utils docs` command. This plugin simply leverages that system to generate the documentation for your Typer CLIs.
1614

17-
I created this plugin because the original plugin was no longer working for me, and I wanted to have a simple plugin that would work with the latest version of Typer. If the original `mkdocs-typer` plugin still works for you, there probably isn't a reason to switch. However, if you are looking for a plugin that will work with the latest version of Typer, this plugin is for you!
15+
I created this plugin because the original plugin was no longer working for me, and I wanted to have a simple plugin that would work with the latest version of Typer. If the original `mkdocs-typer` plugin still works for you, there probably isn't a reason to switch. However, if you are looking for a plugin that will work with the latest version of Typer, this plugin is for you!
1816

1917
- [Read The Docs](https://syn54x.github.io/mkdocs-typer2/)
2018
- [Check out a demo](https://syn54x.github.io/mkdocs-typer2/cli)
@@ -25,6 +23,19 @@ I created this plugin because the original plugin was no longer working for me,
2523
- Automatically generates CLI documentation from your Typer commands
2624
- Supports all Typer command features including arguments, options, and help text
2725
- Easy to configure and use
26+
- `pretty` feature for encapsulating arguments & options inside tables instead of lists
27+
- Global plugin configuration or per-documentation block configuration
28+
29+
## How It Works
30+
31+
The plugin leverages Typer's built-in documentation generation via the `typer <module> utils docs` command to create Markdown documentation. It then processes this Markdown content and integrates it into your MkDocs site.
32+
33+
The plugin works by:
34+
35+
1. Registering a Markdown extension that processes special directive blocks
36+
2. Running the Typer documentation command on your specified module
37+
3. Optionally reformatting the output to use tables for arguments and options (the "pretty" mode)
38+
4. Integrating the resulting HTML into your MkDocs site
2839

2940
## Installation
3041

@@ -34,37 +45,89 @@ Install using pip:
3445
pip install mkdocs-typer2
3546
```
3647

37-
## Usage
48+
### Requirements
49+
50+
- Python 3.10 or higher
51+
- MkDocs 1.6.1 or higher
52+
- Typer 0.12.5 or higher
53+
- Pydantic 2.9.2 or higher
54+
55+
## Configuration
3856

39-
1. Add the plugin to your `mkdocs.yml` file:
57+
### Basic Configuration
58+
59+
Add the plugin to your `mkdocs.yml` file:
4060

4161
```yaml
4262
plugins:
4363
- mkdocs-typer2
4464
```
4565
46-
The plugin offers a `pretty` option that can be set in your `mkdocs.yml` file to enable pretty documentation. This will use markdown tables to format the CLI options and arguments instead of lists.
66+
### Pretty Mode
67+
68+
The plugin offers a `pretty` option that can be set in your `mkdocs.yml` file to enable pretty documentation. This will use markdown tables to format the CLI options and arguments instead of lists:
4769

4870
```yaml
4971
plugins:
5072
- mkdocs-typer2:
5173
pretty: true
5274
```
5375

54-
2. In your Markdown files, use the `:::typer` directive to generate documentation for your Typer CLI
76+
## Usage
77+
78+
### Basic Usage
79+
80+
In your Markdown files, use the `::: mkdocs-typer2` directive to generate documentation for your Typer CLI:
5581

5682
```markdown
5783
::: mkdocs-typer2
5884
:module: my_module
5985
:name: mycli
6086
```
6187

62-
- The `:module:` option is required and specifies the module containing your Typer CLI application. This is the *installed* module, not the directory. I.e: If you app is located in `src/my_module/cli.py`, your `:module:` should typically be `my_module.cli`.
63-
- The `:name:` option is optional and specifies the name of the CLI. If left blank, your CLI will simply be named `CLI` in your documentation.
88+
### Required Parameters
89+
90+
- `:module:` - The module containing your Typer CLI application. This is the *installed* module, not the directory path. For example, if your app is located in `src/my_module/cli.py`, your `:module:` should typically be `my_module.cli`.
91+
92+
### Optional Parameters
93+
94+
- `:name:` - The name of the CLI. If left blank, your CLI will simply be named `CLI` in your documentation.
95+
- `:pretty:` - Set to `true` to enable pretty formatting for this specific documentation block, overriding the global setting.
96+
97+
## Advanced Usage
98+
99+
### Per-Block Pretty Configuration
100+
101+
You can override the global pretty setting for individual documentation blocks:
102+
103+
```markdown
104+
::: mkdocs-typer2
105+
:module: my_module.cli
106+
:name: mycli
107+
:pretty: true
108+
```
109+
110+
### Multiple CLI Documentation
111+
112+
You can document multiple CLIs in the same MkDocs site by using multiple directive blocks:
113+
114+
```markdown
115+
# Main CLI
116+
117+
::: mkdocs-typer2
118+
:module: my_module.cli
119+
:name: mycli
120+
121+
# Admin CLI
122+
123+
::: mkdocs-typer2
124+
:module: my_module.admin
125+
:name: admin-cli
126+
```
64127

65128
## Example
66129

67-
This repository is a good example of how to use the plugin. We have a simple CLI located in `src/mkdocs_typer2/cli.py`.
130+
This repository is a good example of how to use the plugin. We have a simple CLI located in `src/mkdocs_typer2/cli.py`.
68131

69132
The CLI's documentation is automatically generated using the block level directive in `docs/cli.md`:
70133

@@ -73,3 +136,20 @@ The CLI's documentation is automatically generated using the block level directi
73136
:module: mkdocs_typer2.cli
74137
:name: mkdocs-typer2
75138
```
139+
140+
And the pretty version in `docs/cli-pretty.md`:
141+
142+
```markdown
143+
::: mkdocs-typer2
144+
:module: mkdocs_typer2.cli
145+
:name: mkdocs-typer2
146+
:pretty: true
147+
```
148+
149+
## Contributing
150+
151+
Contributions are welcome! Please feel free to submit a Pull Request.
152+
153+
## License
154+
155+
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--8<-- "CHANGELOG.md"

docs/cli-pretty.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: mkdocs-typer2
2+
:module: mkdocs_typer2.cli
3+
:name: mkdocs-typer2
4+
:pretty: true

justfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@default:
2+
just --list
3+
4+
sync:
5+
uv sync
6+
pre-commit install
7+
8+
rm:
9+
rm -rf .venv
10+
11+
test *ARGS:
12+
uv run pytest {{ARGS}}
13+
14+
serve:
15+
uv run mkdocs serve

mkdocs.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ theme:
2626
- toc.follow
2727
watch:
2828
- src/
29+
- README.md
30+
- CHANGELOG.md
2931

3032
nav:
3133
- Home: index.md
32-
- Example CLI: cli.md
33-
- Changelog: changelog.md
34+
- CLI (Old): cli.md
35+
- CLI (Pretty): cli-pretty.md
36+
- CHANGELOG: changelog.md
3437

3538
markdown_extensions:
3639
- abbr
@@ -46,8 +49,7 @@ markdown_extensions:
4649

4750
plugins:
4851
- search
49-
- mkdocs-typer2:
50-
pretty: true
52+
- mkdocs-typer2
5153
- mkdocstrings:
5254
handlers:
5355
python:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mkdocs-typer2"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = "Mkdocs plugin for generating Typer CLI docs"
55
readme = "README.md"
66
requires-python = ">=3.10"

src/mkdocs_typer2/markdown.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,31 @@ def run(self, parent, blocks):
3434
# Extract options from the block
3535
module_match = re.search(r":module:\s*(\S+)", block)
3636
name_match = re.search(r":name:\s*(\S+)", block)
37-
37+
pretty_match = re.search(r":pretty:\s*(\S+)", block)
3838
if not module_match:
3939
raise ValueError("Module is required")
4040

4141
module = module_match.group(1)
4242
name = name_match.group(1) if name_match else ""
4343

44+
# Determine if pretty formatting should be used
45+
# Block-level setting overrides global setting if present
46+
use_pretty = self.pretty # Start with global setting
47+
if pretty_match:
48+
# Parse the block-level setting as a boolean
49+
block_pretty_value = pretty_match.group(1).lower()
50+
if block_pretty_value in ["true", "1", "yes"]:
51+
use_pretty = True
52+
elif block_pretty_value in ["false", "0", "no"]:
53+
use_pretty = False
54+
4455
# Run typer command
4556
cmd = f"typer {module} utils docs --name {name}"
4657
# print(cmd)
4758
result = subprocess.run(cmd.split(), capture_output=True, text=True)
4859

4960
if result.returncode == 0:
50-
if self.pretty:
61+
if use_pretty:
5162
md_content = self.pretty_output(result.stdout)
5263
else:
5364
md_content = result.stdout

0 commit comments

Comments
 (0)