-
Notifications
You must be signed in to change notification settings - Fork 33
/
app.py
68 lines (57 loc) · 2.06 KB
/
app.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This is a fleshed-out application built with Click.
# (Except for the fact that it doesn't do anything!)
#
# Run the command `rich-click app:main --help` to render it with rich-click!
import logging
import click
from rich.logging import RichHandler
logger = logging.getLogger(__name__)
logger.addHandler(RichHandler())
logger.setLevel(logging.INFO)
@click.group("my-app")
@click.option("--environment", "-e",
type=click.Choice(["production", "staging", "integration"]),
default="production",
show_default=True,
help="Environment to run in.")
@click.version_option(version="1.0.1", prog_name="my-app")
def main(environment):
"""CLI for my-app"""
logger.debug("Running in environment=%s", environment)
@main.command("deploy")
@click.argument("version")
@click.pass_context
def deploy(ctx, version):
"""Deploy my-app"""
logger.info("Deploying version=%s in environment=%s", version, ctx.parent.params["environment"])
@main.group("user")
def user_cli():
"""Manage users to my-app"""
@user_cli.command("create")
@click.option("--email", "-e",
required=True,
help="User's email")
@click.password_option("--password", "-p",
required=True,
prompt=True,
help="User's password")
@click.option("--admin",
is_flag=True,
default=False,
help="If flag is passed, give admin permissions")
@click.pass_context
def create(ctx, email, password, admin):
"""Create my-app users"""
if len(password) < 6:
logger.error("Password must be ≥ 6 characters")
ctx.exit(1)
logger.info("Creating user with email=%s admin=%s", email, admin)
@user_cli.command("delete")
@click.argument("user_id",
type=click.INT)
def delete(user_id):
"""Delete my-app users"""
click.confirm(click.style(f"Are you sure you want to delete user={user_id!r}?", fg="red"), abort=True)
logger.info("Deleting user with user_id=%i", user_id)
if __name__ == "__main__":
main()