Skip to content

Commit

Permalink
Merge pull request #132 from DanCardin/dc/markdown-arg-help
Browse files Browse the repository at this point in the history
fix: Route arg help formatting through markdown processing.
  • Loading branch information
DanCardin authored Jun 27, 2024
2 parents 5aab7c7 + 34f7d48 commit 850971e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## 0.22.0
## 0.22

### 0.22.1

- fix: Route arg help formatting through markdown processing.

### 0.22.0

- feat: Allow "attribute docstrings" as additional method of documenting args.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cappa"
version = "0.22.0"
version = "0.22.1"
description = "Declarative CLI argument parser."

repository = "https://github.com/dancardin/cappa"
Expand Down
2 changes: 1 addition & 1 deletion src/cappa/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def add_long_args(help_formatter: HelpFormatter, arg_groups: list[ArgGroup]) ->
if isinstance(arg, Arg):
table.add_row(
Padding(format_arg_name(arg, ", "), help_formatter.left_padding),
Text(format_arg(help_formatter, arg), style=""),
Markdown(format_arg(help_formatter, arg), style=""),
)
else:
for option in arg.available_options():
Expand Down
37 changes: 37 additions & 0 deletions tests/help/test_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
from dataclasses import dataclass

import cappa
import pytest
from rich.console import Console

from tests.utils import backends, parse


@pytest.mark.help
@backends
def test_arg_description_renders_markdown(backend, capsys):
@dataclass
class Args:
foo: str
"""`This` **is** _neat!_"""

with pytest.raises(cappa.Exit):
parse(Args, "--help", backend=backend)

result = capsys.readouterr()

assert "This is neat!" in result.out

with pytest.raises(cappa.Exit):
parse(
Args,
"--help",
backend=backend,
output=cappa.Output(
output_console=Console(force_terminal=True, file=sys.stdout)
),
)

result = capsys.readouterr()
assert "\x1b[1;36;40mThis\x1b[0m \x1b[1mis\x1b[0m \x1b[3mneat!\x1b[0m" in result.out
6 changes: 3 additions & 3 deletions tests/help/test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Args:
Help
[-h, --help] Show this message and exit.
[--completion COMPLETION] Use `--completion generate` to print
shell-specific completion source. Valid options:
generate, complete.
[--completion COMPLETION] Use --completion generate to print shell-specific
completion source. Valid options: generate,
complete.
"""
)

0 comments on commit 850971e

Please sign in to comment.