-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_66.py
More file actions
39 lines (25 loc) · 822 Bytes
/
Copy pathexample_66.py
File metadata and controls
39 lines (25 loc) · 822 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
import typer
"""See https://typer.tiangolo.com/tutorial/commands/context/"""
"""
Using the Context
Exclusive executable callback (see also example_65.py)
We might not always want the callback to be executed if there's already
another command to be executed. To control this, we can get the `typer.Context`
and check if there's an invoked command in `ctx.invoked_subcommand`
"""
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(ctx: typer.Context):
"""
Manage users in the awesome CLI app.
"""
if ctx.invoked_subcommand is None:
print("Initializing database")
if __name__ == "__main__":
app()