Skip to content

Commit

Permalink
🐛 Fix Rich formatting with no commands (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Apr 9, 2024
1 parent c9bc93c commit 3bc7d25
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/test_rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ def secondary():
assert "Hello World" in result.stdout
result = runner.invoke(app, ["secondary"])
assert "Hello Secondary World" in result.stdout


def test_rich_help_no_commands():
"""Ensure that the help still works for a Typer instance with no commands, but with a callback."""
app = typer.Typer(help="My cool Typer app")

@app.callback(invoke_without_command=True, no_args_is_help=True)
def main() -> None:
return None # pragma: no cover

result = runner.invoke(app, ["--help"])

assert result.exit_code == 0
assert "Show this message" in result.stdout
3 changes: 2 additions & 1 deletion typer/rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ def rich_format_help(
len(command.name or "")
for commands in panel_to_commands.values()
for command in commands
]
],
default=0,
)

# Print each command group panel
Expand Down

0 comments on commit 3bc7d25

Please sign in to comment.