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:34 +0000

1"""CLI of fair-python-cookiecutter-demo.""" 

2 

3import typer 

4 

5from fair_python_cookiecutter_demo.lib import CalcOperation, calculate 

6 

7# create subcommand app 

8say = typer.Typer() 

9 

10# create main app 

11app = typer.Typer() 

12app.add_typer(say, name="say") 

13 

14# ---- 

15 

16 

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}") 

22 

23 

24# ---- 

25 

26 

27@say.command() 

28def hello(name: str): 

29 """Greet a person.""" 

30 print(f"Hello {name}") 

31 

32 

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}!")