Skip to content

Commit

Permalink
doc(cli): improve cli reference display
Browse files Browse the repository at this point in the history
- fixes dunders being rendered as bold markdown
- adds the missing space before `(default:`
- monospace some known reccuring references (`pyproject.toml`, `:all`, `:pre` and `:post`)
  • Loading branch information
noirbizarre committed Apr 25, 2023
1 parent 0cf6578 commit dc4513d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docs/docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

```python exec="1" idprefix=""
import argparse
import re
from pdm.core import Core

parser = Core().parser

REPLACEMENTS = {
"pyproject.toml": "`pyproject.toml`",
'":pre"': "`:pre`",
'":post"': "`:post`",
'":all"': "`:all`",
}


def render_parser(
parser: argparse.ArgumentParser, title: str, heading_level: int = 2
Expand Down Expand Up @@ -39,9 +47,15 @@ def render_parser(
line = f"- {', '.join(opts)}"
if action.metavar:
line += f" `{action.metavar}`"
line += f": {action.help}"
# Make dunders monospaced avoiding markdown rendering
help = re.sub(r"__([\w\d\_]+)__", r"`__\1__`", action.help)
# Style env vars: monospaced with italic prefix
help = re.sub(r"env var: ([A-Z_]+)", r"*env var:* `\1`", help)
for string, replacement in REPLACEMENTS.items():
help = help.replace(string, replacement)
line += f": {help}"
if action.default and action.default != argparse.SUPPRESS:
line += f"(default: `{action.default}`)"
line += f" (default: `{action.default}`)"
result.append(line)
result.append("")

Expand Down

0 comments on commit dc4513d

Please sign in to comment.