Skip to content

Commit 6f6a217

Browse files
authored
Merge pull request #50 from clobrano/fix-goto-could-not-find-id
Fix goto CLI handler
2 parents f57a051 + b4a440a commit 6f6a217

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ clean: clean_src
2020

2121
clean_src:
2222
-rm -r src/__pycache__
23+
24+
25+
replace:
26+
make clean && make build && pip install .

src/cli.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ def main():
7878
is_ok, msg = handlers.stop_task_handler(" ".join(args["<time>"]))
7979

8080
elif args["goto"]:
81-
name = " ".join(args["<newtask>"])
82-
tid, is_ok = guess_task_id_from_string(name)
83-
if not is_ok:
84-
msg = f"could not get task ID from: {name}"
85-
86-
is_ok, msg = handlers.goto_task_handler(tid)
81+
description = " ".join(args["<newtask>"])
82+
is_ok, msg = handlers.goto_task_handler(description)
8783

8884
if args["see"]:
8985
if args["<query>"]:

src/handlers.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def autocomplete_handler():
1515
return autocomplete()
1616

1717

18-
def start_task_handler(description: str, start_str: str) -> (bool, str):
18+
def start_task_handler(description: str, start_str: str="") -> (bool, str):
1919
"""handles a request to start a task"""
2020
if not description:
2121
return False, "task description is mandatory"
@@ -70,15 +70,21 @@ def stop_task_handler(stop_time: str) -> (bool, str):
7070
return True, msg
7171

7272

73-
def goto_task_handler(tid: int) -> (bool, str):
73+
def goto_task_handler(description: str) -> (bool, str):
7474
"""handles a request to switch to another task given the ID"""
75-
tasks = get_tasks(lambda x: x.tid == tid)
76-
if not tasks:
77-
return False, f"could not find task with ID {tid}"
78-
task = tasks[0]
75+
if not description:
76+
return False, "task description is mandatory"
77+
78+
if Task.get_running():
79+
now = datetime.now().strftime("%H:%M")
80+
is_ok, msg = stop_task_handler(now)
81+
if not is_ok:
82+
return False, msg
83+
84+
tid, got_id = guess_task_id_from_string(description)
85+
if got_id:
86+
work_on(task_id=tid)
87+
return True, ""
88+
else:
89+
return Task(description).start(), ""
7990

80-
now = datetime.now().strftime("%H:%M")
81-
is_ok, msg = stop_task_handler(now)
82-
if not is_ok:
83-
return False, msg
84-
return start_task_handler(task.name, now)

0 commit comments

Comments
 (0)