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

19 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-19 20:29 +0000

1import typer 1abcdefghi

2from typing_extensions import Annotated 1abcdefghi

3 

4app = typer.Typer() 1abcdefghi

5 

6 

7@app.command() 1abcdefghi

8def create(username: str): 1abcdefghi

9 print(f"Creating user: {username}") 1abcdefghi

10 

11 

12@app.command() 1abcdefghi

13def delete( 1abcdefghi

14 username: str, 

15 force: Annotated[ 

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

17 ], 

18): 

19 if force: 1abcdefghi

20 print(f"Deleting user: {username}") 1abcdefghi

21 else: 

22 print("Operation cancelled") 1abcdefghi

23 

24 

25@app.command() 1abcdefghi

26def delete_all( 1abcdefghi

27 force: Annotated[ 

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

29 ], 

30): 

31 if force: 1abcdefghi

32 print("Deleting all users") 1abcdefghi

33 else: 

34 print("Operation cancelled") 1abcdefghi

35 

36 

37@app.command() 1abcdefghi

38def init(): 1abcdefghi

39 print("Initializing user database") 1abcdefghi

40 

41 

42if __name__ == "__main__": 1abcdefghi

43 app() 1abcdefghi