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

22 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 18:26 +0000

1import typer 1abcdefgh

2 

3app = typer.Typer() 1abcdefgh

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

5 

6 

7@app.command() 1abcdefgh

8def create(username: str): 1abcdefgh

9 if state["verbose"]: 1abcdefgh

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

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

12 if state["verbose"]: 1abcdefgh

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

14 

15 

16@app.command() 1abcdefgh

17def delete(username: str): 1abcdefgh

18 if state["verbose"]: 1abcdefgh

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

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

21 if state["verbose"]: 1abcdefgh

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

23 

24 

25@app.callback() 1abcdefgh

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

27 """ 

28 Manage users in the awesome CLI app. 

29 """ 

30 if verbose: 1abcdefgh

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

32 state["verbose"] = True 1abcdefgh

33 

34 

35if __name__ == "__main__": 1abcdefgh

36 app() 1abcdefgh