Support __main__.py, passing prog_name to callable (#120)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Teymour Aldridge 2020-06-23 12:29:45 +01:00 committed by GitHub
parent f6304f16fd
commit 4ed37fe043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

12
tests/assets/prog_name.py Normal file
View file

@ -0,0 +1,12 @@
import typer
app = typer.Typer()
@app.command()
def main(i: int): # pragma: no cover
pass
if __name__ == "__main__":
app(prog_name="custom-name")

13
tests/test_prog_name.py Normal file
View file

@ -0,0 +1,13 @@
import subprocess
from pathlib import Path
def test_custom_prog_name():
file_path = Path(__file__).parent / "assets/prog_name.py"
result = subprocess.run(
["coverage", "run", str(file_path), "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Usage: custom-name [OPTIONS] I" in result.stdout

View file

@ -209,8 +209,8 @@ class Typer:
)
)
def __call__(self) -> Any:
return get_command(self)()
def __call__(self, *args: Any, **kwargs: Any) -> Any:
return get_command(self)(*args, **kwargs)
def get_group(typer_instance: Typer) -> click.Command: