✨ Support __main__.py, passing prog_name to callable (#120)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
parent
f6304f16fd
commit
4ed37fe043
3 changed files with 27 additions and 2 deletions
12
tests/assets/prog_name.py
Normal file
12
tests/assets/prog_name.py
Normal 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
13
tests/test_prog_name.py
Normal 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
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue