From cb5b4fae29446016cd19abb35f5a7e7ef566ae3e Mon Sep 17 00:00:00 2001 From: KKlochko Date: Fri, 24 Mar 2023 21:42:00 +0200 Subject: [PATCH] (Added) update label option for source. --- CHANGELOG.org | 2 ++ tui_rsync/cli/source/source_update.py | 29 +++++++++++++++++++++++++++ tui_rsync/models/models.py | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.org b/CHANGELOG.org index 9394071..33d6688 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -39,4 +39,6 @@ Added *remove all* option for sources. ** 0.8.6 <2023-03-23 Thu> Added *remove all* option for groups. +** 0.8.6 <2023-03-23 Thu> + Added *update label* option for source. diff --git a/tui_rsync/cli/source/source_update.py b/tui_rsync/cli/source/source_update.py index 94573b6..d03fd1d 100644 --- a/tui_rsync/cli/source/source_update.py +++ b/tui_rsync/cli/source/source_update.py @@ -28,6 +28,35 @@ from tui_rsync.cli.label_prompt import LabelPrompt console = Console() source_update = typer.Typer() +@source_update.command() +def label( + label: str = typer.Option( + None, "--label", "-l", + help="[b]The label[/] is a uniq identification of a [b]source[/].", + show_default=False + ), + new_label: str = typer.Option( + None, "--new-label", "-nl", + help="[b]The new label[/] will replace the [b]old source label[/].", + show_default=False + ), + +): + """ + [green b]Update[/] an [yellow]existing source label[/]. + """ + if label is None: + console.print("What is the [yellow b]old label of source[/]? ") + label = LabelPrompt.get_label_fzf() + + if new_label is None: + question = "What is the [yellow b]new label of source[/]? " + new_label = LabelPrompt.ask_uuid(question) + + if Source.is_exist(label): + src = Source.get_source(label) + src.update_label(new_label) + @source_update.command() def args( label: str = typer.Option( diff --git a/tui_rsync/models/models.py b/tui_rsync/models/models.py index 11ca06d..da7c16c 100644 --- a/tui_rsync/models/models.py +++ b/tui_rsync/models/models.py @@ -82,6 +82,10 @@ class Source(BaseModel): src.save() return src + def update_label(self, new_label): + self.label = new_label + self.save() + def update_args(self, args): args_obj = SyncCommand.get_sync_command(args) self.args = args_obj