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

19 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 

5app = typer.Typer() 1abcdefghij

6 

7 

8@app.command() 1abcdefghij

9def create(username: str): 1abcdefghij

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

11 

12 

13@app.command() 1abcdefghij

14def delete( 1abcdefghij

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: 1abcdefghij

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

22 else: 

23 print("Operation cancelled") 1abcdefghij

24 

25 

26@app.command() 1abcdefghij

27def delete_all( 1abcdefghij

28 force: Annotated[ 

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

30 ], 

31): 

32 if force: 1abcdefghij

33 print("Deleting all users") 1abcdefghij

34 else: 

35 print("Operation cancelled") 1abcdefghij

36 

37 

38@app.command() 1abcdefghij

39def init(): 1abcdefghij

40 print("Initializing user database") 1abcdefghij

41 

42 

43if __name__ == "__main__": 1abcdefghij

44 app() 1abcdefghij