-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_65.py
More file actions
42 lines (26 loc) · 807 Bytes
/
Copy pathexample_65.py
File metadata and controls
42 lines (26 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import typer
"""See https://typer.tiangolo.com/tutorial/commands/context/"""
"""
Using the Context
By default, the callback is only executed right before executing a command.
And if no command is provided, the help message is shown.
But you can make it run even without a subcommand with
`invoke_without_command=True`
If you run `python example_65.py`, the callback is executed, we don't get the
default help message:
"""
app = typer.Typer()
@app.command()
def create(username: str):
print(f"Creating user: {username}")
@app.command()
def delete(username: str):
print(f"Deleting user: {username}")
@app.callback(invoke_without_command=True)
def main():
"""
Manage users in the awesome CLI app.
"""
print("Initializing database")
if __name__ == "__main__":
app()