Coverage for frappe_manager / commands / delete.py: 65%
17 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:13 +0530
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:13 +0530
1from typing import Annotated
3import typer
4from typer_examples import example
6from frappe_manager import CLI_BENCHES_DIRECTORY
7from frappe_manager.output_manager import get_global_output_handler
8from frappe_manager.site_manager.bench_service import BenchService
9from frappe_manager.utils.callbacks import sitename_callback, sites_autocompletion_callback
12@example(
13 "Delete a bench",
14 "{benchname}",
15 detail="Deletes the bench directory and associated containers. This is destructive and will remove local bench data.",
16 benchname="mybench",
17)
18@example(
19 "Delete without confirmation",
20 "{benchname} --yes",
21 detail="Performs deletion without interactive confirmation. Use with caution in scripts or automation.",
22 benchname="mybench",
23)
24@example(
25 "Delete bench and its database from global-db",
26 "{benchname} --delete-db-from-global-db",
27 detail="Also deletes the bench's database from the global-db service. This permanently removes stored site data.",
28 benchname="mybench",
29)
30def delete(
31 ctx: typer.Context,
32 benchname: Annotated[
33 str | None,
34 typer.Argument(
35 help="Name of the bench.",
36 autocompletion=sites_autocompletion_callback,
37 callback=sitename_callback,
38 ),
39 ] = None,
40 yes: Annotated[bool, typer.Option("--yes", "-y", help="Skip confirmation prompts")] = False,
41 delete_db_from_global_db: Annotated[
42 bool | None,
43 typer.Option(
44 "--delete-db-from-global-db/--no-delete-db-from-global-db",
45 help="Delete database from global-db service",
46 ),
47 ] = None,
48):
49 """
50 Delete a bench and optionally its database from global-db service.
52 Removes the bench directory, containers, and associated data. Use --yes to avoid confirmation prompts.
53 """
55 if benchname:
56 services_manager = ctx.obj["services"]
57 verbose = ctx.obj["verbose"]
59 output = get_global_output_handler()
60 bench_service = BenchService(CLI_BENCHES_DIRECTORY, services_manager, verbose=verbose, output_handler=output)
61 bench_service.delete_bench(benchname, yes=yes, delete_db_from_global_db=delete_db_from_global_db)