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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix context_settings for a Typer app with a single command #210

Merged
merged 7 commits into from Jul 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_others.py
Expand Up @@ -232,3 +232,14 @@ def main(arg1, arg2: int, arg3: "int", arg4: bool = False, arg5: "bool" = False)
"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
9 changes: 8 additions & 1 deletion typer/main.py
Expand Up @@ -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)
Expand Down