Project 16 of 20, for Paul
Command-Line To-Do Tool
Paul's to-do list for the course code, on the Workshop terminal: add, list and done, kept in a file between runs, and polite when it's used wrongly.
Sign up free to open itLog in
Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- PaulMy to-dos are in comments all over the course code, and there were forty of them at the last count.
- PaulEvery time Neil asks what's left to do, I have to go hunting through the files.
- PaulI want a list on the terminal we can both run, to add a job, see the list and tick one off.
- PaulIt should still be there tomorrow, and when it can't help it should say so, in words and in the exit code.
Write todo.py, a command-line to-do list kept in todo.json: a JSON list of tasks, each {"number": 1, "task": "rename x in grades.py", "done": false}. Use argparse, with three commands:
add TASKputs the task on the end, numbered one more than the highest so far (1 for the first), saves the list, and printsAdded 4: fix the clock.listprints every task as1 [ ] rename x in grades.py, or[x]when it's done.list --openleaves out the done ones. An empty list printsNothing on the list.done NUMBERticks that task off, saves the list, and printsDone: retrain the spam filter, orAlready done: mark the Act I tests.
--file NAME, before the command, keeps the list in another file. A file that isn't there yet is an empty list. Two things are failures: say so on sys.stderr and exit with 1:
There's no task 9.todo.json isn't a to-do list I can read., for a file that isn't JSON
A command it doesn't know, or a number that isn't one, is a usage error: argparse deals with those, with exit code 2.
$ python todo.py add "fix the clock" Added 4: fix the clock $ python todo.py done 3 Done: retrain the spam filter $ python todo.py list 1 [ ] rename x in grades.py 2 [x] mark the Act I tests 3 [x] retrain the spam filter 4 [ ] fix the clock
What you learn
What's in it
- Words after the program's name
- What was typed
- How it finished
- Stop everything
- Let argparse read it
- argparse reads it for you
- Commands of its own
- Done, number three
- How Paul would do it
- Fix Aaesha's version
- Make the to-do tool
- Ship it