Coverage for docs_src / commands / options / tutorial001_an_py310.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-26 21:46 +0000

1from typing import Annotated 1abcdefg

2 

3import typer 1abcdefg

4 

5app = typer.Typer() 1abcdefg

6 

7 

8@app.command() 1abcdefg

9def create(username: str): 1abcdefg

10 print(f"Creating user: {username}") 1abcdefg

11 

12 

13@app.command() 1abcdefg

14def delete( 1abcdefg

15 username: str, 

16 force: Annotated[ 

17 bool, typer.Option(prompt="Are you sure you want to delete the user?") 

18 ], 

19): 

20 if force: 1abcdefg

21 print(f"Deleting user: {username}") 1abcdefg

22 else: 

23 print("Operation cancelled") 1abcdefg

24 

25 

26@app.command() 1abcdefg

27def delete_all( 1abcdefg

28 force: Annotated[ 

29 bool, typer.Option(prompt="Are you sure you want to delete ALL users?") 

30 ], 

31): 

32 if force: 1abcdefg

33 print("Deleting all users") 1abcdefg

34 else: 

35 print("Operation cancelled") 1abcdefg

36 

37 

38@app.command() 1abcdefg

39def init(): 1abcdefg

40 print("Initializing user database") 1abcdefg

41 

42 

43if __name__ == "__main__": 1abcdefg

44 app() 1abcdefg