Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix Rich formatting with no commands #796

Merged
merged 5 commits into from
Apr 9, 2024
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
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
Loading