diff --git a/tests/test_others.py b/tests/test_others.py index 2060a86..ad433ad 100644 --- a/tests/test_others.py +++ b/tests/test_others.py @@ -232,3 +232,14 @@ def test_forward_references(): "arg1: Hello\narg2: 2\narg3: 3\narg4: True\narg5: True\n" in result.stdout ) + + +def test_context_settings_inheritance_single_command(): + app = typer.Typer(context_settings=dict(help_option_names=["-h", "--help"])) + + @app.command() + def main(name: str): + pass # pragma: nocover + + result = runner.invoke(app, ["main", "-h"]) + assert "Show this message and exit." in result.stdout diff --git a/typer/main.py b/typer/main.py index d2a4584..386ede9 100644 --- a/typer/main.py +++ b/typer/main.py @@ -236,7 +236,14 @@ def get_command(typer_instance: Typer) -> click.Command: return click_command elif len(typer_instance.registered_commands) == 1: # Create a single Command - click_command = get_command_from_info(typer_instance.registered_commands[0]) + single_command = typer_instance.registered_commands[0] + + if not single_command.context_settings and not isinstance( + typer_instance.info.context_settings, DefaultPlaceholder + ): + single_command.context_settings = typer_instance.info.context_settings + + click_command = get_command_from_info(single_command) if typer_instance._add_completion: click_command.params.append(click_install_param) click_command.params.append(click_show_param)