Coverage for docs_src / options / version / tutorial002.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1from typing import Annotated 1abcdefghij

2 

3import typer 1abcdefghij

4 

5__version__ = "0.1.0" 1abcdefghij

6 

7app = typer.Typer() 1abcdefghij

8 

9 

10def version_callback(value: bool): 1abcdefghij

11 if value: 1abcdefghij

12 print(f"Awesome CLI Version: {__version__}") 1abcdefghij

13 raise typer.Exit() 1abcdefghij

14 

15 

16def name_callback(name: str): 1abcdefghij

17 if name != "Camila": 1abcdefghij

18 raise typer.BadParameter("Only Camila is allowed") 1abcdefghij

19 return name 1abcdefghij

20 

21 

22@app.command() 1abcdefghij

23def main( 1abcdefghij

24 name: Annotated[str, typer.Option(callback=name_callback)], 

25 version: Annotated[ 

26 bool | None, typer.Option("--version", callback=version_callback) 

27 ] = None, 

28): 

29 print(f"Hello {name}") 1abcdefghij

30 

31 

32if __name__ == "__main__": 1abcdefghij

33 app() 1abcdefghij