fm code 'add a --json flag to todo.py that prints the tasks as a JSON list, with a test' --worker claude
Plan FEATURE S · Add --json flag to todo.py that prints tasks as a JSON list
Steps
- Write test_todo.py (unittest) that calls main(['--json']) with captured stdout and asserts json.loads(output) == TASKS, plus a check that main([]) still prints the numbered list; confirm it fails
- In todo.py add `import json` and, in main, if '--json' in argv print json.dumps(TASKS) and return, leaving the numbered output otherwise unchanged
- Run the test and the shell checks to confirm they pass
Checks
- PASS Running `python todo.py --json` prints TASKS as a JSON list that parses back to the same list
python todo.py --json | python -c "import sys, json; assert json.load(sys.stdin) == ['buy milk', 'write report']"(failed before the work) - PASS Running `python todo.py` with no flag still prints the numbered list, and `--json` output is not numbered text
python todo.py | grep -qx '1. buy milk' && ! python todo.py --json | grep -q '^1\. ' && python todo.py --json | grep -q '^\['(failed before the work) - PASS A test in test_todo.py covers the --json output and passes
python -m unittest test_todo(failed before the work)
Changed
test_todo.py+25todo.py+4
Closed T-0001 closed; committed a1bc78b (2 files). Undo: git revert --no-edit a1bc78b (tokens: 99493 in, 989 out)