import logging

import click
from caprover_api import caprover_api
from environs import Env

logging.basicConfig(level=logging.DEBUG)

env = Env()

cap = caprover_api.CaproverAPI(
    dashboard_url=env.str("CAPROVER_DOMAIN"),
    password=env.str("CAPROVER_PASSWORD"),
)


@click.command()
@click.option(
    "-a",
    "--app-name",
    default="vbv-feature-*",
    help="app name pattern to delete, can contain * as wildcard",
)
@click.option(
    "--automated/--no-automated",
    default=False,
    help="`automated` deletes without confirmation",
)
def main(app_name, automated):
    print(f"delete all apps with name {app_name}")
    cap.delete_app_matching_pattern(
        app_name_pattern=app_name,
        delete_volumes=True,
        automated=automated,
    )


if __name__ == "__main__":
    main()
