Skip to content
Myr

🐛 Fix `context_settings` for a Typer app with a single command (#210)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Leron Gray · committed by GitHub · parent e663db0 · Browse files · 2 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

Diff stats

2 files+19 added−1 removed

  • tests:+11 added−0 removed
  • other:+8 added−1 removed

2 files+19 added−1 removed

modified:tests/test_others.py+11 added
230 unmodified lines
231 assert (232 "arg1: <class 'str'> Hello\narg2: <class 'int'> 2\narg3: <class 'int'> 3\narg4: <class 'bool'> True\narg5: <class 'bool'> True\n"233 in result.stdout234 )235236237def test_context_settings_inheritance_single_command():238 app = typer.Typer(context_settings=dict(help_option_names=["-h", "--help"]))239240 @app.command()241 def main(name: str):242 pass # pragma: nocover243244 result = runner.invoke(app, ["main", "-h"])245 assert "Show this message and exit." in result.stdout
modified:typer/main.py+8 added-1 removed
234 unmodified lines
235 click_command.params.append(click_show_param)236 return click_command237 elif len(typer_instance.registered_commands) == 1:238 # Create a single Command239 click_command = get_command_from_info(typer_instance.registered_commands[0])239 single_command = typer_instance.registered_commands[0]240241 if not single_command.context_settings and not isinstance(242 typer_instance.info.context_settings, DefaultPlaceholder243 ):244 single_command.context_settings = typer_instance.info.context_settings245246 click_command = get_command_from_info(single_command)247 if typer_instance._add_completion:248 click_command.params.append(click_install_param)249 click_command.params.append(click_show_param)250 return click_command
621 unmodified lines