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

11 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 

16@app.command() 1abcdefghij

17def main( 1abcdefghij

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

19 version: Annotated[ 

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

21 ] = None, 

22): 

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

24 

25 

26if __name__ == "__main__": 1abcdefghij

27 app() 1abcdefghij