Coverage for docs_src / commands / help / tutorial001.py: 100%

19 statements  

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

1from typing import Annotated 1abcdefghij

2 

3import typer 1abcdefghij

4 

5app = typer.Typer(help="Awesome CLI user manager.") 1abcdefghij

6 

7 

8@app.command() 1abcdefghij

9def create(username: str): 1abcdefghij

10 """ 

11 Create a new user with username. 

12 """ 

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

14 

15 

16@app.command() 1abcdefghij

17def delete( 1abcdefghij

18 username: str, 

19 force: Annotated[ 

20 bool, 

21 typer.Option( 

22 prompt="Are you sure you want to delete the user?", 

23 help="Force deletion without confirmation.", 

24 ), 

25 ], 

26): 

27 """ 

28 Delete a user with username. 

29 

30 If --force is not used, will ask for confirmation. 

31 """ 

32 if force: 1abcdefghij

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

34 else: 

35 print("Operation cancelled") 1abcdefghij

36 

37 

38@app.command() 1abcdefghij

39def delete_all( 1abcdefghij

40 force: Annotated[ 

41 bool, 

42 typer.Option( 

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

44 help="Force deletion without confirmation.", 

45 ), 

46 ], 

47): 

48 """ 

49 Delete ALL users in the database. 

50 

51 If --force is not used, will ask for confirmation. 

52 """ 

53 if force: 1abcdefghij

54 print("Deleting all users") 1abcdefghij

55 else: 

56 print("Operation cancelled") 1abcdefghij

57 

58 

59@app.command() 1abcdefghij

60def init(): 1abcdefghij

61 """ 

62 Initialize the users database. 

63 """ 

64 print("Initializing user database") 1abcdefghij

65 

66 

67if __name__ == "__main__": 1abcdefghij

68 app() 1abcdefghij