diff --git a/tui_rsync/user_interface/cli/components/backup_plan/backup_plan.py b/tui_rsync/user_interface/cli/components/backup_plan/backup_plan.py index 7e50825..9124d63 100644 --- a/tui_rsync/user_interface/cli/components/backup_plan/backup_plan.py +++ b/tui_rsync/user_interface/cli/components/backup_plan/backup_plan.py @@ -22,8 +22,10 @@ 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 +from .update_backup_plan import update_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") +backup_plan.add_typer(update_backup_plan, name="update", help="Update backup plans") diff --git a/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py b/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py new file mode 100644 index 0000000..6b45100 --- /dev/null +++ b/tui_rsync/user_interface/cli/components/backup_plan/update_backup_plan.py @@ -0,0 +1,67 @@ +################################################################################ +# Copyright (C) 2023-2025 Kostiantyn Klochko # +# # +# This file is part of tui-rsync. # +# # +# tui-rsync is free software: you can redistribute it and/or modify it under # +# the 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 . # +################################################################################ + +from rich.console import Console +from typing import List, Optional +import typer + +from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService +from tui_rsync.core.components.backup_plan.domain import BackupPlan, Source, Destination, BackupPlanId +from tui_rsync.core.shared_kernel.components.common import Label +from tui_rsync.infrastructure.configuration import CurrentConfiguration + + +console = Console() +update_backup_plan = typer.Typer() + + +@update_backup_plan.command() +def replace( + id: str = typer.Option( + None, "--id", "-i", + help="[b]The id[/] is an uniq identification of a [b]backup plan[/].", + show_default=False + ), + label: str = typer.Option( + '', "--label", "-l", + help="[b]The label[/] is a uniq identification of a [b]source[/].", + show_default=False + ), + source: str = typer.Option( + None, "--source", "-s", + help="[b]A source[/] of the data.", + show_default=False + ), + destinations: Optional[List[str]] = typer.Option( + None, "--destination", "-d", help="[b]The backup[/] destinations.", + show_default=False + ) +): + """ + [green b]Replace[/] a [yellow]backup plan[/] with a [bold]id[/] with [y]new data[/]. + """ + + if source is None: + source = console.input("What is the [yellow b]path to the source[/]? ") + + service: BackupPlanService = CurrentConfiguration.get(BackupPlanService) + + plan = BackupPlan(id=BackupPlanId(id), label=Label(label), source=Source(source), destinations=[Destination(path) for path in destinations]) + service.update(plan) +