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

22 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

4state = {"verbose": False} 1abcdefghij

5 

6 

7@app.command() 1abcdefghij

8def create(username: str): 1abcdefghij

9 if state["verbose"]: 1abcdefghij

10 print("About to create a user") 1abcdefghij

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

12 if state["verbose"]: 1abcdefghij

13 print("Just created a user") 1abcdefghij

14 

15 

16@app.command() 1abcdefghij

17def delete(username: str): 1abcdefghij

18 if state["verbose"]: 1abcdefghij

19 print("About to delete a user") 1abcdefghij

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

21 if state["verbose"]: 1abcdefghij

22 print("Just deleted a user") 1abcdefghij

23 

24 

25@app.callback() 1abcdefghij

26def main(verbose: bool = False): 1abcdefghij

27 """ 

28 Manage users in the awesome CLI app. 

29 """ 

30 if verbose: 1abcdefghij

31 print("Will write verbose output") 1abcdefghij

32 state["verbose"] = True 1abcdefghij

33 

34 

35if __name__ == "__main__": 1abcdefghij

36 app() 1abcdefghij