diff --git a/tests/test_rich_utils.py b/tests/test_rich_utils.py index b6da8995f6..c62e3512aa 100644 --- a/tests/test_rich_utils.py +++ b/tests/test_rich_utils.py @@ -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 diff --git a/typer/rich_utils.py b/typer/rich_utils.py index 2b91f265ab..cf0538e914 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -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