Permalink
Browse files

Upgraded t.

  • Loading branch information...
1 parent 884f5e0 commit 55b963b91f633fc82ef66ed87370c37b67b3d42f @sorin-ionescu committed Dec 15, 2011
Showing with 29 additions and 6 deletions.
  1. +29 −6 bin/t
View
35 bin/t
@@ -51,8 +51,10 @@ def _task_from_taskline(taskline):
and other metadata will be generated when the line is read. This is
supported to enable editing of the taskfile with a simple text editor.
"""
- if '|' in taskline:
- text, _, meta = taskline.partition('|')
+ if taskline.strip().startswith('#'):
+ return None
+ elif '|' in taskline:
+ text, _, meta = taskline.rpartition('|')
task = { 'text': text.strip() }
for piece in meta.strip().split(','):
label, data = piece.split(':')
@@ -136,7 +138,8 @@ class TaskDict(object):
tls = [tl.strip() for tl in tfile if tl]
tasks = map(_task_from_taskline, tls)
for task in tasks:
- getattr(self, kind)[task['id']] = task
+ if task is not None:
+ getattr(self, kind)[task['id']] = task
def __getitem__(self, prefix):
"""Return the unfinished task with the given prefix.
@@ -192,6 +195,17 @@ class TaskDict(object):
task = self.tasks.pop(self[prefix]['id'])
self.done[task['id']] = task
+ def remove_task(self, prefix):
+ """Remove the task from tasks list.
+
+ If more than one task matches the prefix an AmbiguousPrefix exception
+ will be raised, if no tasks match it an UnknownPrefix exception will
+ be raised.
+
+ """
+ self.tasks.pop(self[prefix]['id'])
+
+
def print_list(self, kind='tasks', verbose=False, quiet=False, grep=''):
"""Print out a nicely formatted list of unfinished tasks."""
tasks = dict(getattr(self, kind).items())
@@ -234,6 +248,8 @@ def _build_parser():
help="edit TASK to contain TEXT", metavar="TASK")
actions.add_option("-f", "--finish", dest="finish",
help="mark TASK as finished", metavar="TASK")
+ actions.add_option("-r", "--remove", dest="remove",
+ help="Remove TASK from list", metavar="TASK")
parser.add_option_group(actions)
config = OptionGroup(parser, "Configuration Options")
@@ -255,6 +271,9 @@ def _build_parser():
output.add_option("-q", "--quiet",
action="store_true", dest="quiet", default=False,
help="print less detailed output (no task ids, etc)")
+ output.add_option("--done",
+ action="store_true", dest="done", default=False,
+ help="list done tasks instead of unfinished ones")
parser.add_option_group(output)
return parser
@@ -270,19 +289,23 @@ def _main():
if options.finish:
td.finish_task(options.finish)
td.write(options.delete)
+ elif options.remove:
+ td.remove_task(options.remove)
+ td.write(options.delete)
elif options.edit:
td.edit_task(options.edit, text)
td.write(options.delete)
elif text:
td.add_task(text)
td.write(options.delete)
else:
- td.print_list(verbose=options.verbose, quiet=options.quiet,
+ kind = 'tasks' if not options.done else 'done'
+ td.print_list(kind=kind, verbose=options.verbose, quiet=options.quiet,
grep=options.grep)
except AmbiguousPrefix, e:
- sys.stderr.write('The ID "%s" matches more than one task.' % e.prefix)
+ sys.stderr.write('The ID "%s" matches more than one task.\n' % e.prefix)
except UnknownPrefix, e:
- sys.stderr.write('The ID "%s" does not match any task.' % e.prefix)
+ sys.stderr.write('The ID "%s" does not match any task.\n' % e.prefix)
if __name__ == '__main__':

0 comments on commit 55b963b

Please sign in to comment.