mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
Add the restore command.
This commit is contained in:
@@ -22,8 +22,11 @@ from rich.console import Console
|
||||
import typer
|
||||
|
||||
from tui_rsync.core.shared_kernel.components.backup.application.service import BackupSyncService
|
||||
from tui_rsync.core.shared_kernel.components.backup.application.service.backup_restore_service import \
|
||||
BackupRestoreService
|
||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||
from tui_rsync.infrastructure.configuration import CurrentConfiguration
|
||||
from tui_rsync.user_interface.cli.shared_kernel.components.prompts.applications.prompts import ChoosePromptFzf
|
||||
|
||||
console = Console()
|
||||
sync = typer.Typer()
|
||||
@@ -42,7 +45,7 @@ def one(
|
||||
)
|
||||
):
|
||||
"""
|
||||
[green b]Sync[/] a [yellow]source[/] with the [yellow b]label[/] and its backups.
|
||||
[green b]Sync[/] a [yellow]source[/] to [yellow]destination[/] for the [yellow b]backup plan id[/].
|
||||
[yellow b]Skips[/] if not available.
|
||||
"""
|
||||
|
||||
@@ -54,3 +57,31 @@ def one(
|
||||
|
||||
# TODO add args
|
||||
service.sync_by_plan_id(UUID(id), '-avuP', dry)
|
||||
|
||||
|
||||
@sync.command()
|
||||
def restore(
|
||||
id: str = typer.Option(
|
||||
None, "--id", "-i",
|
||||
help="[b]The id[/] is an uniq identification of a [b]backup plan[/].",
|
||||
show_default=False
|
||||
),
|
||||
dry: bool = typer.Option(
|
||||
False, "-d", "--dry-run",
|
||||
help="The command will [b]show[/] information about what will be changed.",
|
||||
)
|
||||
):
|
||||
"""
|
||||
[green b]Sync[/] a [yellow]destination[/] to the [yellow]source[/] for the [yellow b]backup plan id[/].
|
||||
[yellow b]Skips[/] if not available.
|
||||
"""
|
||||
|
||||
service: BackupRestoreService = CurrentConfiguration.get(BackupRestoreService)
|
||||
choose_prompt: ChoosePromptFzf = CurrentConfiguration.get(ChoosePromptFzf)
|
||||
|
||||
if id is None:
|
||||
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
||||
return
|
||||
|
||||
# TODO add args
|
||||
service.sync_by_plan_id(UUID(id), choose_prompt, '-avuP', dry)
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
from .choose_prompt_port import ChoosePromptPort
|
||||
from .fzf_prompt import ChoosePromptFzf
|
||||
|
||||
__all__ = ['ChoosePromptPort', 'ChoosePromptFzf']
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ChoosePromptPort(ABC):
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def choose(iterator) -> str:
|
||||
pass
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
from .choose_prompt_port import ChoosePromptPort
|
||||
from pyfzf import FzfPrompt
|
||||
|
||||
|
||||
class ChoosePromptFzf(ChoosePromptPort):
|
||||
@staticmethod
|
||||
def choose(iterator) -> str:
|
||||
fzf = FzfPrompt()
|
||||
return fzf.prompt(iterator)[0]
|
||||
Reference in New Issue
Block a user