Skip to content

Commit

Permalink
feat: enable multiple task id choice on picker
Browse files Browse the repository at this point in the history
  • Loading branch information
u8slvn committed Sep 4, 2024
1 parent f144967 commit 12f9817
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/hyperfocus/console/commands/_shortcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/hyperfocus/console/commands/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/hyperfocus/console/commands/stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_console/test_commands/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
27 changes: 23 additions & 4 deletions tests/test_console/test_commands/test_stash/test_stash_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 12f9817

Please sign in to comment.