Add the remove commands.

Fixed deleting to remove destinations with a backup plan.
This commit is contained in:
2025-01-09 21:55:54 +02:00
parent ea5d98490d
commit ea0cc3dab0
5 changed files with 89 additions and 1 deletions
@@ -21,7 +21,9 @@
import typer
from .add_backup_plan import add_backup_plan
from .show_backup_plan import show_backup_plan
from .remove_backup_plan import remove_backup_plan
backup_plan = add_backup_plan
backup_plan.add_typer(show_backup_plan, name="show", help="Show backup plans")
backup_plan.add_typer(remove_backup_plan, name="remove", help="Remove backup plans")
@@ -0,0 +1,74 @@
################################################################################
# Copyright (C) 2023 Kostiantyn Klochko <kostya_klochko@ukr.net> #
# #
# This file is part of tui-rsync. #
# #
# tui-rsync is free software: you can redistribute it and/or modify it under #
# uthe terms of the GNU General Public License as published by the Free #
# Software Foundation, either version 3 of the License, or (at your option) #
# any later version. #
# #
# tui-rsync is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
# details. #
# #
# You should have received a copy of the GNU General Public License along with #
# tui-rsync. If not, see <https://www.gnu.org/licenses/>. #
################################################################################
from rich.console import Console
import typer
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
from tui_rsync.core.shared_kernel.components.common import UUID
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
console = Console()
remove_backup_plan = typer.Typer()
@remove_backup_plan.command()
def one(
id: str = typer.Option(
None, "--id", "-i",
help="[b]The id[/] is an uniq identification of a [b]backup plan[/].",
show_default=False
)
):
"""
[red b]Remove[/] an [yellow]existing backup plan[/].
"""
db = SqliteDatabaseManager()
repository = BackupPlanRepository(db)
service = BackupPlanService(repository)
if id is None:
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
return
plan = service.delete(UUID(id))
if plan is None:
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
return
console.print(f"Removed the backup plan with {id}.")
@remove_backup_plan.command()
def all():
"""
[red b]Remove[/] [yellow] all existing backup plans[/].
"""
db = SqliteDatabaseManager()
removed = RemoveAllBackupBackupPlansCommand().execute()
if removed:
console.print(f"Removed all backup plans.")
else:
console.print(f"Nothing to remove. No backup plans.")