🐛 Fix context_settings
for a Typer app with a single command (#210)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
e663db02cd
commit
778d5bdb61
2 changed files with 19 additions and 1 deletions
|
@ -232,3 +232,14 @@ def test_forward_references():
|
|||
"arg1: <class 'str'> Hello\narg2: <class 'int'> 2\narg3: <class 'int'> 3\narg4: <class 'bool'> True\narg5: <class 'bool'> 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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue