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

13 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

4 

5__version__ = "0.1.0" 1habcdefg

6 

7 

8def version_callback(value: bool): 1habcdefg

9 if value: 1habcdefg

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

11 raise typer.Exit() 1habcdefg

12 

13 

14def name_callback(name: str): 1habcdefg

15 if name != "Camila": 1habcdefg

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

17 return name 1habcdefg

18 

19 

20def main( 1abcdefg

21 name: str = typer.Option(..., callback=name_callback), 

22 version: Optional[bool] = typer.Option( 

23 None, "--version", callback=version_callback, is_eager=True 

24 ), 

25): 

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

27 

28 

29if __name__ == "__main__": 1habcdefg

30 typer.run(main) 1habcdefg