Skip to content

Commit d8d2e4b

Browse files
author
Ziang Zhang
committed
fix: only parse quoted args in add_task, remove dead test code
- add_task now only splits on quotes when args actually starts with a quote character. Plain multi-word input like 'buy groceries' is treated as the full task text, not split into task + category. - Remove dead _fake_import_module function from test_help_docs.py (was overridden by the lambda on the next line). Addresses CodeRabbit review on TruFoundation#53 and TruFoundation#59.
1 parent 36b6908 commit d8d2e4b

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

tests/test_help_docs.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
from __future__ import annotations
22

3-
import importlib
43
from types import SimpleNamespace
54

65
from trushell.commands.core import run_help
76

87

98
def test_run_help_prints_docstring_for_known_command(monkeypatch, capsys):
10-
def _fake_import_module(path: str):
11-
module = importlib.import_module(path.replace("/", ".").removesuffix(".py"))
12-
return module
13-
149
fake_kernel = SimpleNamespace(
1510
registry={
1611
"settings": {
1712
"path": "trushell/commands/settings.py",
1813
"function": "run_settings",
1914
}
2015
},
21-
_import_module=_fake_import_module,
2216
)
2317

2418
# Provide a minimal module object with the expected function and

trushell/commands/tasks.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,30 @@ def add_task(args: str) -> None:
1212
"""Add a new task to the todo list.
1313
1414
Supports two formats:
15-
addtask "task text" "category"
16-
addtask task text here
15+
addtask "task text" "category" — explicit quotes
16+
addtask task text here — entire text is the task
1717
"""
1818
if not args.strip():
1919
typer.secho('⚠️ Missing arguments. Syntax: addtask "task-name" "category"', fg=typer.colors.YELLOW)
2020
return
2121

22-
# Try to parse quoted arguments: "task text" "category"
22+
# Only parse as "task" "category" when the user explicitly used quotes.
23+
# Otherwise treat the entire args as the task text.
2324
import shlex
24-
try:
25-
parts = shlex.split(args)
26-
except ValueError:
27-
parts = args.strip().split(maxsplit=1)
28-
29-
if len(parts) >= 2:
30-
task_text = parts[0]
31-
category = parts[1]
25+
stripped = args.strip()
26+
if stripped.startswith('"') or stripped.startswith("'"):
27+
try:
28+
parts = shlex.split(stripped)
29+
except ValueError:
30+
parts = None
31+
if parts and len(parts) >= 2:
32+
task_text = parts[0]
33+
category = parts[1]
34+
else:
35+
task_text = stripped.strip('"').strip("'")
36+
category = "General"
3237
else:
33-
task_text = parts[0]
38+
task_text = stripped
3439
category = "General"
3540

3641
todo = Todo(task=task_text, category=category)

0 commit comments

Comments
 (0)