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

19 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1import typer 1iabcdefgh

2from typing_extensions import Annotated 1iabcdefgh

3 

4app = typer.Typer() 1iabcdefgh

5 

6 

7@app.command() 1iabcdefgh

8def create(username: str): 1iabcdefgh

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

10 

11 

12@app.command() 1iabcdefgh

13def delete( 1abcdefgh

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

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

21 else: 

22 print("Operation cancelled") 1iabcdefgh

23 

24 

25@app.command() 1iabcdefgh

26def delete_all( 1abcdefgh

27 force: Annotated[ 

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

29 ], 

30): 

31 if force: 1iabcdefgh

32 print("Deleting all users") 1iabcdefgh

33 else: 

34 print("Operation cancelled") 1iabcdefgh

35 

36 

37@app.command() 1iabcdefgh

38def init(): 1abcdefgh

39 print("Initializing user database") 1iabcdefgh

40 

41 

42if __name__ == "__main__": 1iabcdefgh

43 app() 1iabcdefgh