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

18 statements  

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

1import typer 1abcdefghij

2 

3app = typer.Typer() 1abcdefghij

4 

5 

6@app.command() 1abcdefghij

7def create(username: str): 1abcdefghij

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

9 

10 

11@app.command() 1abcdefghij

12def delete( 1abcdefghij

13 username: str, 

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

15): 

16 if force: 1abcdefghij

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

18 else: 

19 print("Operation cancelled") 1abcdefghij

20 

21 

22@app.command() 1abcdefghij

23def delete_all( 1abcdefghij

24 force: bool = typer.Option( 

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

26 ), 

27): 

28 if force: 1abcdefghij

29 print("Deleting all users") 1abcdefghij

30 else: 

31 print("Operation cancelled") 1abcdefghij

32 

33 

34@app.command() 1abcdefghij

35def init(): 1abcdefghij

36 print("Initializing user database") 1abcdefghij

37 

38 

39if __name__ == "__main__": 1abcdefghij

40 app() 1abcdefghij