Skip to content

Commit

Permalink
Keep --help as part of options raw output (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florimond Manca committed Feb 17, 2021
1 parent 65a9de2 commit afda7b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mkdocs_click/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ def _make_options(ctx: click.Context) -> Iterator[str]:
"""Create the Markdown lines describing the options for the command."""
formatter = ctx.make_formatter()
click.Command.format_options(ctx.command, ctx, formatter)

option_lines = formatter.getvalue().splitlines()

# First line is redundant "Options"
# Last line is `--help`
option_lines = formatter.getvalue().splitlines()[1:-1]
if not option_lines:
return
option_lines = option_lines[1:]

if not option_lines: # pragma: no cover
# We expect at least `--help` to be present.
raise RuntimeError("Expected at least one option")

yield "Options:"
yield ""
Expand Down
19 changes: 19 additions & 0 deletions tests/app/expected.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Usage:
cli [OPTIONS] COMMAND [ARGS]...
```

Options:

```
--help Show this message and exit.
```

## bar

The bar command
Expand All @@ -18,6 +24,12 @@ Usage:
cli bar [OPTIONS] COMMAND [ARGS]...
```

Options:

```
--help Show this message and exit.
```

### hello

Simple program that greets NAME for a total of COUNT times.
Expand All @@ -33,6 +45,7 @@ Options:
```
--count INTEGER Number of greetings.
--name TEXT The person to greet.
--help Show this message and exit.
```

## foo
Expand All @@ -42,3 +55,9 @@ Usage:
```
cli foo [OPTIONS]
```

Options:

```
--help Show this message and exit.
```
8 changes: 8 additions & 0 deletions tests/unit/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def hello():
```
-d, --debug TEXT Include debug output
--help Show this message and exit.
```
"""
Expand Down Expand Up @@ -80,6 +81,12 @@ def test_custom_multicommand():
multi [OPTIONS] COMMAND [ARGS]...
```
Options:
```
--help Show this message and exit.
```
## hello
Hello, world!
Expand All @@ -94,6 +101,7 @@ def test_custom_multicommand():
```
-d, --debug TEXT Include debug output
--help Show this message and exit.
```
"""
).lstrip()
Expand Down

0 comments on commit afda7b3

Please sign in to comment.