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

18 statements  

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

1import typer 1abcdefg

2 

3app = typer.Typer() 1abcdefg

4 

5 

6@app.command() 1abcdefg

7def create(username: str): 1abcdefg

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

9 

10 

11@app.command() 1abcdefg

12def delete( 1abcdefg

13 username: str, 

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

15): 

16 if force: 1abcdefg

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

18 else: 

19 print("Operation cancelled") 1abcdefg

20 

21 

22@app.command() 1abcdefg

23def delete_all( 1abcdefg

24 force: bool = typer.Option( 

25 ..., prompt="Are you sure you want to delete ALL users?" 

26 ), 

27): 

28 if force: 1abcdefg

29 print("Deleting all users") 1abcdefg

30 else: 

31 print("Operation cancelled") 1abcdefg

32 

33 

34@app.command() 1abcdefg

35def init(): 1abcdefg

36 print("Initializing user database") 1abcdefg

37 

38 

39if __name__ == "__main__": 1abcdefg

40 app() 1abcdefg