Skip to content

Commit 7bbc77e

Browse files
author
Ziang Zhang
committed
fix: pass category argument through to add_task properly
The add_task() function hardcoded category='General' regardless of user input, and _handle_todo_command() concatenated both arguments into a single string, discarding the category. Fix: - Update add_task() to parse quoted arguments via shlex.split() - Update _handle_todo_command() to pass arguments with quotes preserved Closes TruFoundation#46
1 parent 1a29752 commit 7bbc77e

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

trushell/cli.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
def app_with_lower() -> None:
2828
"""Entry point that normalizes the first argument to lowercase for case-insensitive invocation."""
29-
if len(sys.argv) > 1:
30-
# Create a local copy to avoid mutating the global sys.argv
31-
argv_copy = sys.argv.copy()
32-
if argv_copy[1].lower() not in {"--help", "-h", "version"}:
33-
raw = " ".join(argv_copy[1:])
29+
# Create a local copy to avoid mutating the global sys.argv
30+
argv = sys.argv.copy()
31+
if len(argv) > 1:
32+
if argv[1].lower() not in {"--help", "-h", "version"}:
33+
raw = " ".join(argv[1:]).lower()
3434
get_kernel().execute_command(raw)
3535
return
3636

@@ -193,7 +193,7 @@ def _handle_todo_command(command: str) -> bool:
193193
if add_match:
194194
from trushell.commands.tasks import add_task
195195

196-
add_task(f"{add_match.group(1)} {add_match.group(2)}")
196+
add_task(f'"{add_match.group(1)}" "{add_match.group(2)}"')
197197
return True
198198

199199
update_match = re.match(r'updatetask\s+(\d+)\s+"([^"]+)"\s+"([^"]+)"', command)

trushell/commands/tasks.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,31 @@
77

88

99
def add_task(args: str) -> None:
10-
"""Add a new task to the todo list. The full remainder is treated as the task."""
10+
"""Add a new task to the todo list.
11+
12+
Supports two formats:
13+
addtask "task text" "category"
14+
addtask task text here
15+
"""
1116
if not args.strip():
12-
print("Usage: task add <task>")
17+
print("Usage: task add <task> [category]")
1318
return
1419

15-
task_text = args.strip()
16-
todo = Todo(task=task_text, category="General")
20+
# Try to parse quoted arguments: "task text" "category"
21+
import shlex
22+
try:
23+
parts = shlex.split(args)
24+
except ValueError:
25+
parts = args.strip().split(maxsplit=1)
26+
27+
if len(parts) >= 2:
28+
task_text = parts[0]
29+
category = parts[1]
30+
else:
31+
task_text = parts[0]
32+
category = "General"
33+
34+
todo = Todo(task=task_text, category=category)
1735
insert_todo(todo)
1836
print("Task added.")
1937

0 commit comments

Comments
 (0)