Coverage for src/fair_python_cookiecutter_demo/cli.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-08-01 13:35 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-08-01 13:35 +0000
1"""CLI of fair-python-cookiecutter-demo."""
3import typer
5from fair_python_cookiecutter_demo.lib import CalcOperation, calculate
7# create subcommand app
8say = typer.Typer()
10# create main app
11app = typer.Typer()
12app.add_typer(say, name="say")
14# ----
17@app.command()
18def calc(op: CalcOperation, x: int, y: int):
19 """Compute the result of applying an operation on x and y."""
20 result: int = calculate(op, x, y)
21 typer.echo(f"Result: {result}")
24# ----
27@say.command()
28def hello(name: str):
29 """Greet a person."""
30 print(f"Hello {name}")
33@say.command()
34def goodbye(name: str, formal: bool = False):
35 """Say goodbye to a person."""
36 if formal:
37 print(f"Goodbye {name}. Have a good day.")
38 else:
39 print(f"Bye {name}!")