Skip to content

Commit c7d957c

Browse files
🐛 Avoid printing additional output with no_args_is_help=True and Click 8.2 (#1278)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 55f190e commit c7d957c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tests/test_tutorial/test_commands/test_index/test_tutorial003.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def test_no_arg():
1818
assert "delete" in result.output
1919

2020

21+
def test_no_additional_output():
22+
"""Ensure that no additional output was generated (cf. PR #1262)"""
23+
result = runner.invoke(app)
24+
assert result.output.count("Usage") == 1
25+
assert "Error" not in result.output
26+
27+
2128
def test_create():
2229
result = runner.invoke(app, ["create"])
2330
assert result.exit_code == 0

typer/rich_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ def rich_format_error(self: click.ClickException) -> None:
693693
Called by custom exception handler to print richly formatted click errors.
694694
Mimics original click.ClickException.echo() function but with rich formatting.
695695
"""
696+
# Don't do anything when it's a NoArgsIsHelpError (without importing it, cf. #1278)
697+
if self.__class__.__name__ == "NoArgsIsHelpError":
698+
return
699+
696700
console = _get_rich_console(stderr=True)
697701
ctx: Union[click.Context, None] = getattr(self, "ctx", None)
698702
if ctx is not None:

0 commit comments

Comments
 (0)