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

19 statements  

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

1from typing import Annotated 1abcdefgh

2 

3import typer 1abcdefgh

4 

5app = typer.Typer() 1abcdefgh

6 

7 

8@app.command() 1abcdefgh

9def create(username: str): 1abcdefgh

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

11 

12 

13@app.command() 1abcdefgh

14def delete( 1abcdefgh

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

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

22 else: 

23 print("Operation cancelled") 1abcdefgh

24 

25 

26@app.command() 1abcdefgh

27def delete_all( 1abcdefgh

28 force: Annotated[ 

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

30 ], 

31): 

32 if force: 1abcdefgh

33 print("Deleting all users") 1abcdefgh

34 else: 

35 print("Operation cancelled") 1abcdefgh

36 

37 

38@app.command() 1abcdefgh

39def init(): 1abcdefgh

40 print("Initializing user database") 1abcdefgh

41 

42 

43if __name__ == "__main__": 1abcdefgh

44 app() 1abcdefgh