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

11 statements  

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

1from typing import Annotated, Optional 1abcdefgh

2 

3import typer 1abcdefgh

4 

5__version__ = "0.1.0" 1abcdefgh

6 

7app = typer.Typer() 1abcdefgh

8 

9 

10def version_callback(value: bool): 1abcdefgh

11 if value: 1abcdefgh

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

13 raise typer.Exit() 1abcdefgh

14 

15 

16@app.command() 1abcdefgh

17def main( 1abcdefgh

18 name: Annotated[str, typer.Option()] = "World", 

19 version: Annotated[ 

20 Optional[bool], typer.Option("--version", callback=version_callback) 

21 ] = None, 

22): 

23 print(f"Hello {name}") 1abcdefgh

24 

25 

26if __name__ == "__main__": 1abcdefgh

27 app() 1abcdefgh