diff --git a/tui_rsync/main.py b/tui_rsync/main.py index 32daa04..c5e54c7 100644 --- a/tui_rsync/main.py +++ b/tui_rsync/main.py @@ -1,7 +1,8 @@ +from tui_rsync.user_interface.cli.cli import cli_app def main(): - pass + cli_app() if __name__ == "__main__": main() diff --git a/tui_rsync/user_interface/cli/__init__.py b/tui_rsync/user_interface/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tui_rsync/user_interface/cli/cli.py b/tui_rsync/user_interface/cli/cli.py new file mode 100644 index 0000000..ed68a0d --- /dev/null +++ b/tui_rsync/user_interface/cli/cli.py @@ -0,0 +1,26 @@ +################################################################################ +# 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 # +# 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 . # +################################################################################ + +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") diff --git a/tui_rsync/user_interface/cli/components/__init__.py b/tui_rsync/user_interface/cli/components/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tui_rsync/user_interface/cli/components/backup_plan/__init__.py b/tui_rsync/user_interface/cli/components/backup_plan/__init__.py new file mode 100644 index 0000000..c089125 --- /dev/null +++ b/tui_rsync/user_interface/cli/components/backup_plan/__init__.py @@ -0,0 +1,3 @@ +from .backup_plan import backup_plan + +__all__ = ['backup_plan'] diff --git a/tui_rsync/user_interface/cli/components/backup_plan/add_backup_plan.py b/tui_rsync/user_interface/cli/components/backup_plan/add_backup_plan.py new file mode 100644 index 0000000..261919d --- /dev/null +++ b/tui_rsync/user_interface/cli/components/backup_plan/add_backup_plan.py @@ -0,0 +1,66 @@ +################################################################################ +# 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 # +# 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 . # +################################################################################ + +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) + 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 new file mode 100644 index 0000000..54f2284 --- /dev/null +++ b/tui_rsync/user_interface/cli/components/backup_plan/backup_plan.py @@ -0,0 +1,27 @@ +################################################################################ +# 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 # +# 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 . # +################################################################################ + + +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")