Add the CLI command to add a backup plan.

dev
KKlochko 4 months ago
parent 4bfdcf066b
commit 027fee47a6

@ -1,7 +1,8 @@
from tui_rsync.user_interface.cli.cli import cli_app
def main():
pass
cli_app()
if __name__ == "__main__":
main()

@ -0,0 +1,26 @@
################################################################################
# Copyright (C) 2023-2025 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 .components.backup_plan import backup_plan
console = Console()
cli_app = typer.Typer(rich_markup_mode="rich")
cli_app.add_typer(backup_plan, name="plans", help="Manage backup plans")

@ -0,0 +1,3 @@
from .backup_plan import backup_plan
__all__ = ['backup_plan']

@ -0,0 +1,66 @@
################################################################################
# Copyright (C) 2023-2025 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
from typing import List, Optional
import typer
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.components.backup_plan.domain import BackupPlan, Source, Destination
from tui_rsync.core.shared_kernel.components.common import Label
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
console = Console()
add_backup_plan = typer.Typer()
@add_backup_plan.command()
def add(
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]Create[/] a [yellow]new backup plan[/] with a [bold]uniq[/] label.
[b]The source[/] will be connected to [b]backup destinations[/].
"""
if source is None:
source = console.input("What is the [yellow b]path to the source[/]? ")
db = SqliteDatabaseManager()
repository = BackupPlanRepository(db)
service = BackupPlanService(repository)
plan = BackupPlan(label=Label(label), source=Source(source), destinations=[Destination(path) for path in destinations])
service.add(plan)

@ -0,0 +1,27 @@
################################################################################
# Copyright (C) 2023-2025 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/>. #
################################################################################
import typer
from .add_backup_plan import add_backup_plan
from .show_backup_plan import show_backup_plan
backup_plan = add_backup_plan
backup_plan.add_typer(show_backup_plan, name="show", help="Show backup plans")
Loading…
Cancel
Save