Skip to content

Conversation

@Ox54
Copy link
Contributor

@Ox54 Ox54 commented Jun 3, 2025

Pull Request: Add Support for Parsing and Rendering Command Tables in Markdown CLI Docs

Summary

This PR enhances the pretty.py module to support parsing and rendering a Commands section in CLI documentation. The changes allow the system to recognize, store, and output tables of subcommands (with names and descriptions) in both the markdown-to-tree and tree-to-markdown conversions.

Details

  • New Model:

    • Added a CommandEntry Pydantic model to represent individual commands with name and description fields.
    • Updated the CommandNode model to include a commands: List[CommandEntry] field.
  • Markdown Parsing (parse_markdown_to_tree):

    • Recognizes the **Commands**: section in markdown.
    • Parses each command entry (name and description) and adds it to the commands list of the current command node.
    • Handles both the standard * name: description and fallback * name`` formats.
  • Markdown Rendering (tree_to_markdown):

    • Adds a "Commands" table to the generated markdown if any commands are present.
    • Formats the table with columns for "Name" and "Description".
  • Other Improvements:

    • Ensures section state is correctly managed when switching between arguments, options, and commands.
    • Adds tests for edge cases in command parsing and rendering.

Motivation

This change makes the CLI documentation more comprehensive by including a structured list of subcommands, improving both the parsing of existing markdown and the generation of new documentation.

Example

A markdown section like:

**Commands**:
* `serve`: Start the server
* `build`: Build the project

Will now be parsed into the tree and rendered back as a markdown table.


Closes: #16

@Ox54 Ox54 self-assigned this Jun 3, 2025
@Ox54 Ox54 added the bug Something isn't working label Jun 3, 2025
@codecov
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mkdocs_typer2/pretty.py 85.18% 4 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #17      +/-   ##
==========================================
- Coverage   96.98%   95.57%   -1.41%     
==========================================
  Files           5        5              
  Lines         199      226      +27     
==========================================
+ Hits          193      216      +23     
- Misses          6       10       +4     
Files with missing lines Coverage Δ
src/mkdocs_typer2/cli.py 100.00% <100.00%> (ø)
src/mkdocs_typer2/pretty.py 94.63% <85.18%> (-2.10%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a384c2a...d882a95. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ox54 Ox54 merged commit 215bc50 into main Jun 3, 2025
3 of 4 checks passed
@Ox54 Ox54 deleted the Ox54/issue16 branch June 3, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants