From 12f9817c48bc22ce29c38c782ff1a975113997ec Mon Sep 17 00:00:00 2001 From: u8slvn Date: Wed, 4 Sep 2024 10:48:58 +0200 Subject: [PATCH] feat: enable multiple task id choice on picker --- .../console/commands/_shortcodes.py | 8 ++++-- src/hyperfocus/console/commands/delete.py | 3 +-- src/hyperfocus/console/commands/stash.py | 3 +-- .../test_console/test_commands/test_delete.py | 2 +- .../test_stash/test_stash_push.py | 27 ++++++++++++++++--- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/hyperfocus/console/commands/_shortcodes.py b/src/hyperfocus/console/commands/_shortcodes.py index f4aea92..4ef8946 100644 --- a/src/hyperfocus/console/commands/_shortcodes.py +++ b/src/hyperfocus/console/commands/_shortcodes.py @@ -7,6 +7,7 @@ import click +from hyperfocus.console.core import parameters from hyperfocus.console.exceptions import HyperfocusExit from hyperfocus.console.exceptions import TaskError from hyperfocus.database.models import TaskStatus @@ -44,6 +45,10 @@ def pick_task(self, prompt_text: str) -> int: self.show_tasks() return cast(int, prompt.prompt(prompt_text, type=click.INT)) + def pick_tasks(self, prompt_text: str) -> tuple[int]: + self.show_tasks() + return tuple(prompt.prompt(prompt_text, type=parameters.INT_LIST)) + def get_task(self, task_id: int) -> Task: task = self.session.daily_tracker.get_task(task_id) if not task: @@ -53,8 +58,7 @@ def get_task(self, task_id: int) -> Task: def get_tasks(self, task_ids: tuple[int, ...], prompt_text: str) -> list[Task]: if not task_ids: - task_id = self.pick_task(prompt_text=prompt_text) - task_ids = (task_id,) + task_ids = self.pick_tasks(prompt_text=prompt_text) tasks = [] for task_id in task_ids: diff --git a/src/hyperfocus/console/commands/delete.py b/src/hyperfocus/console/commands/delete.py index 7acc34c..85d6af4 100644 --- a/src/hyperfocus/console/commands/delete.py +++ b/src/hyperfocus/console/commands/delete.py @@ -20,8 +20,7 @@ def delete(task_ids: tuple[int, ...], force: bool) -> None: if force: if not task_ids: - task_id = task_cmd.pick_task(prompt_text="Force delete task") - task_ids = (task_id,) + task_ids = task_cmd.pick_tasks(prompt_text="Force delete task(s)") for task_id in task_ids: task = task_cmd.get_task(task_id=task_id) diff --git a/src/hyperfocus/console/commands/stash.py b/src/hyperfocus/console/commands/stash.py index 130fcd4..3cad457 100644 --- a/src/hyperfocus/console/commands/stash.py +++ b/src/hyperfocus/console/commands/stash.py @@ -33,8 +33,7 @@ def push(task_ids: tuple[int, ...] | None) -> None: stash_box = StashBox(session.daily_tracker) if not task_ids: - task_id = task_cmd.pick_task(prompt_text="Stash task") - task_ids = (task_id,) + task_ids = task_cmd.pick_tasks(prompt_text="Stash task(s)") for task_id in task_ids: task = session.daily_tracker.get_task(task_id) diff --git a/tests/test_console/test_commands/test_delete.py b/tests/test_console/test_commands/test_delete.py index 67a8bb0..67b5c5c 100644 --- a/tests/test_console/test_commands/test_delete.py +++ b/tests/test_console/test_commands/test_delete.py @@ -65,7 +65,7 @@ def test_force_delete(cli): " --------------------- \n" f" 1 {icons.TASK_STATUS} foo {icons.NO_DETAILS} \n" "\n" - f"{icons.PROMPT} Force delete task: 12\n" + f"{icons.PROMPT} Force delete task(s): 12\n" f"{icons.ERROR}(error) Task 12 does not exist.\n" ) diff --git a/tests/test_console/test_commands/test_stash/test_stash_push.py b/tests/test_console/test_commands/test_stash/test_stash_push.py index aee9f23..45bb27e 100644 --- a/tests/test_console/test_commands/test_stash/test_stash_push.py +++ b/tests/test_console/test_commands/test_stash/test_stash_push.py @@ -40,16 +40,35 @@ def test_stash_push_with_ids(cli): def test_stash_push_without_id(cli): runner.invoke(cli, ["add", "foo"]) + runner.invoke(cli, ["add", "bar"]) + runner.invoke(cli, ["add", "foobar"]) result = runner.invoke(cli, ["stash", "push"], input="1\n") assert result.exit_code == 0 assert result.output == ( "\n" - " # tasks details \n" - " --------------------- \n" - f" 1 {icons.TASK_STATUS} foo {icons.NO_DETAILS} \n" + " # tasks details \n" + " ------------------------ \n" + f" 1 {icons.TASK_STATUS} foo {icons.NO_DETAILS} \n" + f" 2 {icons.TASK_STATUS} bar {icons.NO_DETAILS} \n" + f" 3 {icons.TASK_STATUS} foobar {icons.NO_DETAILS} \n" "\n" - "? Stash task: 1\n" + "? Stash task(s): 1\n" "✔(success) Task: #1 ⬢ foo stashed.\n" ) + + result = runner.invoke(cli, ["stash", "push"], input="2 3\n") + + assert result.exit_code == 0 + assert result.output == ( + "\n" + " # tasks details \n" + " ------------------------ \n" + f" 2 {icons.TASK_STATUS} bar {icons.NO_DETAILS} \n" + f" 3 {icons.TASK_STATUS} foobar {icons.NO_DETAILS} \n" + "\n" + "? Stash task(s): 2 3\n" + "✔(success) Task: #2 ⬢ bar stashed.\n" + "✔(success) Task: #3 ⬢ foobar stashed.\n" + )