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

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1from typing import Optional 1habcdefg

2 

3import typer 1habcdefg

4from typing_extensions import Annotated 1habcdefg

5 

6__version__ = "0.1.0" 1habcdefg

7 

8 

9def version_callback(value: bool): 1habcdefg

10 if value: 1habcdefg

11 print(f"Awesome CLI Version: {__version__}") 1habcdefg

12 raise typer.Exit() 1habcdefg

13 

14 

15def name_callback(name: str): 1habcdefg

16 if name != "Camila": 1habcdefg

17 raise typer.BadParameter("Only Camila is allowed") 1habcdefg

18 return name 1habcdefg

19 

20 

21def main( 1abcdefg

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

23 version: Annotated[ 

24 Optional[bool], 

25 typer.Option("--version", callback=version_callback, is_eager=True), 

26 ] = None, 

27): 

28 print(f"Hello {name}") 1habcdefg

29 

30 

31if __name__ == "__main__": 1habcdefg

32 typer.run(main) 1habcdefg