docs(_ext): Add pretty_argparse extension with CLI usage highlighting by tony · Pull Request #1007 · tmux-python/tmuxp · GitHub
Skip to content

docs(_ext): Add pretty_argparse extension with CLI usage highlighting#1007

Merged
tony merged 4 commits intomasterfrom
pretty-argparse-extension
Jan 11, 2026
Merged

docs(_ext): Add pretty_argparse extension with CLI usage highlighting#1007
tony merged 4 commits intomasterfrom
pretty-argparse-extension

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented Jan 11, 2026

Summary

A comprehensive Sphinx extension that enhances sphinx-argparse output:

  • Strip ANSI escape codes from argparse help text (FORCE_COLOR support)
  • Transform "examples:" definition lists into proper documentation sections
  • Nest category-specific examples under parent Examples section
  • Custom Pygments lexer (cli-usage) for usage block syntax highlighting
  • Reorder sections so usage appears before examples

CLI usage lexer token types

Token Type Examples
usage: prefix Generic.Heading usage:
Long options Name.Tag --verbose, --no-color
Short options Name.Attribute -h, -S
Option values Name.Variable socket-path, COMMAND
Uppercase metavars Name.Constant FILE, PATH
Positional args Name.Label session-name
Brackets Punctuation [, ], (, )
Operators Operator `

Files added

  • docs/_ext/pretty_argparse.py: Main extension (680 lines)
  • docs/_ext/cli_usage_lexer.py: Pygments lexer (116 lines)
  • tests/docs/_ext/test_pretty_argparse.py: 66 tests (854 lines)
  • tests/docs/_ext/test_cli_usage_lexer.py: 22 tests (357 lines)

Test plan

  • uv run ruff check . passes
  • uv run mypy . passes
  • uv run py.test tests/docs/_ext/ passes (88 tests)
  • Docs build successfully with syntax-highlighted usage blocks

tony added 3 commits January 10, 2026 18:55
Add Pygments type stubs to dev and lint dependency groups.
Also add sphinxarg.* to mypy ignore_missing_imports.
A comprehensive Sphinx extension that enhances sphinx-argparse output:

Features:
- Strip ANSI escape codes from argparse help text (FORCE_COLOR support)
- Transform "examples:" definition lists into proper doc sections
- Nest category-specific examples under parent Examples section
- Custom Pygments lexer (cli-usage) for usage block syntax highlighting
- Reorder sections so usage appears before examples

CLI usage lexer token types:
- Generic.Heading: "usage:" prefix
- Name.Tag: long options (--verbose, --no-color)
- Name.Attribute: short options (-h, -S)
- Name.Variable: option values (socket-path, COMMAND)
- Name.Constant: uppercase metavars (FILE, PATH)
- Name.Label: positional args and command names
- Punctuation: brackets [], parentheses ()
- Operator: pipe | and equals =

Files added:
- docs/_ext/pretty_argparse.py: Main extension (680 lines)
- docs/_ext/cli_usage_lexer.py: Pygments lexer (116 lines)
- tests/docs/_ext/test_pretty_argparse.py: 66 tests (854 lines)
- tests/docs/_ext/test_cli_usage_lexer.py: 22 tests (357 lines)
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 11, 2026

Sphinx extension files (pretty_argparse.py, cli_usage_lexer.py) are
documentation infrastructure, not core application code. Exclude them
from coverage measurement similar to tests/, _vendor/, etc.
@tony tony merged commit 509b5d7 into master Jan 11, 2026
14 checks passed
@tony tony deleted the pretty-argparse-extension branch January 11, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant