Skip to content
Closed
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
7 changes: 6 additions & 1 deletion src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ def get_completion_args(self) -> tuple[list[str], str]:

def format_completion(self, item: CompletionItem) -> str:
if item.help:
return f"{item.type},{item.value}\t{item.help}"
help_ = " ".join(
part.strip() for part in item.help.splitlines() if part.strip()
)

if help_:
return f"{item.type},{item.value}\t{help_}"

return f"{item.type},{item.value}"

Expand Down
27 changes: 27 additions & 0 deletions tests/test_shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,33 @@ def test_full_complete(runner, shell, env, expect):
assert result.output == expect


def test_fish_complete_multiline_help(runner):
cli = Command(
"cli",
params=[
Option(
["--at"],
help="Attachment with explicit mimetype,\n--at image.jpg image/jpeg",
)
],
)

result = runner.invoke(
cli,
env={
"_CLI_COMPLETE": "fish_complete",
"COMP_WORDS": "cli --",
"COMP_CWORD": "--",
},
)

assert (
result.output
== "plain,--at\tAttachment with explicit mimetype, --at image.jpg image/jpeg\n"
"plain,--help\tShow this message and exit.\n"
)


@pytest.mark.parametrize(
("env", "expect"),
[
Expand Down