Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Remove explicit reference to `click.BaseCommand` and `click.MultiCommand` objects in anticipation of their deprecation. (Pull #82)
- Properly ensure whitespace is trimmed from the usage string. (Pull #83)
- Propagate `context_settings` to `click.Context`-like objects. (Pull #79)
- Allow commands with no options. (Pull #84)

## 0.8.1 - 2023-09-18

Expand Down
13 changes: 10 additions & 3 deletions mkdocs_click/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ def _make_plain_options(ctx: click.Context, show_hidden: bool = False) -> Iterat
# First line is redundant "Options"
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")
# It's possible to define a command with no options, especially common when
# forwarding arguments to an external process.
if not option_lines:
return

yield "**Options:**"
yield ""
Expand Down Expand Up @@ -335,6 +336,12 @@ def _make_table_options(ctx: click.Context, show_hidden: bool = False) -> Iterat

options = [param for param in ctx.command.get_params(ctx) if isinstance(param, click.Option)]
options = [option for option in options if not option.hidden or show_hidden]

# It's possible to define a command with no options, especially common when
# forwarding arguments to an external process.
if not options:
return

option_rows = [_format_table_option_row(option) for option in options]

yield "**Options:**"
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ dependencies = [
]
[tool.hatch.envs.test.scripts]
test = [
"pytest -q {args}",
"pytest {args}",
"bash .tools/test.sh {args}",
]
[tool.hatch.envs.test.overrides]
platform.windows.scripts = [
{ key = "test", value = "pytest {args}" },
]

[tool.hatch.envs.types]
dependencies = [
Expand Down
27 changes: 27 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def hello_ascii_art():
"""


@click.command(context_settings={"help_option_names": []})
def hello_no_options():
"""
Hello, world!
"""


HELLO_EXPECTED = dedent(
"""
# hello
Expand All @@ -64,6 +71,21 @@ def hello_ascii_art():
).lstrip()


HELLO_EXPECTED_NO_OPTIONS = dedent(
"""
# hello

Hello, world!

**Usage:**

```text
hello [OPTIONS]
```
"""
).lstrip()


def test_basic():
output = "\n".join(make_command_docs("hello", hello))
assert output == HELLO_EXPECTED
Expand Down Expand Up @@ -97,6 +119,11 @@ def test_basic_ascii_art():
assert output == HELLO_EXPECTED


def test_basic_no_options():
output = "\n".join(make_command_docs("hello", hello_no_options))
assert output == HELLO_EXPECTED_NO_OPTIONS


@click.command()
@click.option("-d", "--debug", help="Include debug output")
@click.option("--choice", type=click.Choice(["foo", "bar"]), default="foo")
Expand Down