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

19 statements  

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

1from typing import Annotated 1abcdefgh

2 

3import typer 1abcdefgh

4 

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

6 

7 

8@app.command() 1abcdefgh

9def create(username: str): 1abcdefgh

10 """ 

11 Create a new user with USERNAME. 

12 """ 

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

14 

15 

16@app.command() 1abcdefgh

17def delete( 1abcdefgh

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

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

34 else: 

35 print("Operation cancelled") 1abcdefgh

36 

37 

38@app.command() 1abcdefgh

39def delete_all( 1abcdefgh

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

54 print("Deleting all users") 1abcdefgh

55 else: 

56 print("Operation cancelled") 1abcdefgh

57 

58 

59@app.command() 1abcdefgh

60def init(): 1abcdefgh

61 """ 

62 Initialize the users database. 

63 """ 

64 print("Initializing user database") 1abcdefgh

65 

66 

67if __name__ == "__main__": 1abcdefgh

68 app() 1abcdefgh