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

18 statements  

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

1import typer 1iabcdefgh

2 

3app = typer.Typer(help="Awesome CLI user manager.") 1iabcdefgh

4 

5 

6@app.command() 1iabcdefgh

7def create(username: str): 1iabcdefgh

8 """ 

9 Create a new user with USERNAME. 

10 """ 

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

12 

13 

14@app.command() 1iabcdefgh

15def delete( 1abcdefgh

16 username: str, 

17 force: bool = typer.Option( 

18 ..., 

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

20 help="Force deletion without confirmation.", 

21 ), 

22): 

23 """ 

24 Delete a user with USERNAME. 

25 

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

27 """ 

28 if force: 1iabcdefgh

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

30 else: 

31 print("Operation cancelled") 1iabcdefgh

32 

33 

34@app.command() 1iabcdefgh

35def delete_all( 1abcdefgh

36 force: bool = typer.Option( 

37 ..., 

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

39 help="Force deletion without confirmation.", 

40 ), 

41): 

42 """ 

43 Delete ALL users in the database. 

44 

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

46 """ 

47 if force: 1iabcdefgh

48 print("Deleting all users") 1iabcdefgh

49 else: 

50 print("Operation cancelled") 1iabcdefgh

51 

52 

53@app.command() 1iabcdefgh

54def init(): 1abcdefgh

55 """ 

56 Initialize the users database. 

57 """ 

58 print("Initializing user database") 1iabcdefgh

59 

60 

61if __name__ == "__main__": 1iabcdefgh

62 app() 1iabcdefgh