# HG changeset patch # User Steve Losh # Date 1316559135 14400 # Node ID 44d920ae117e7e3b7790d76179e120cac9224d42 # Parent 2e3102258623a49519e72d130528e815e67704f3# Parent 65b004631139c07343611a2cbbaaceae8f0caabc Merge. diff -r 65b004631139 -r 44d920ae117e t.py --- a/t.py Thu Sep 01 22:29:33 2011 +0530 +++ b/t.py Tue Sep 20 18:52:15 2011 -0400 @@ -54,7 +54,7 @@ if taskline.strip().startswith('#'): return None elif '|' in taskline: - text, _, meta = taskline.partition('|') + text, _, meta = taskline.rpartition('|') task = { 'text': text.strip() } for piece in meta.strip().split(','): label, data = piece.split(':') @@ -195,6 +195,17 @@ 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. + + """ + task = 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()) @@ -237,6 +248,8 @@ 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") @@ -258,6 +271,9 @@ 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 @@ -273,6 +289,9 @@ 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) @@ -280,12 +299,13 @@ 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__': diff -r 65b004631139 -r 44d920ae117e tests/basic.t --- a/tests/basic.t Thu Sep 01 22:29:33 2011 +0530 +++ b/tests/basic.t Tue Sep 20 18:52:15 2011 -0400 @@ -12,12 +12,21 @@ $ xt 3 - Sample one. 7 - Sample two. + $ xt 'this | that' + $ xt + 3 - Sample one. + 4 - this | that + 7 - Sample two. Finishing tasks: $ xt -f 3 $ xt + 4 - this | that 7 - Sample two. $ xt -f 7 $ xt + 4 - this | that + $ xt -f 4 + $ xt diff -r 65b004631139 -r 44d920ae117e tests/editing.t --- a/tests/editing.t Thu Sep 01 22:29:33 2011 +0530 +++ b/tests/editing.t Tue Sep 20 18:52:15 2011 -0400 @@ -10,10 +10,23 @@ $ xt -e a New sample. $ xt a - New sample. + $ xt 'this | that' + $ xt + 4 - this | that + a - New sample. + $ xt -e 4 'this &| that' + $ xt + 4 - this &| that + a - New sample. Sed-style substitution: $ xt -e a 's/New/Testing/' $ xt + 4 - this &| that + a - Testing sample. + $ xt -e 4 '/this &/this /' + $ xt + 4 - this | that a - Testing sample. diff -r 65b004631139 -r 44d920ae117e tests/finished.t --- a/tests/finished.t Thu Sep 01 22:29:33 2011 +0530 +++ b/tests/finished.t Tue Sep 20 18:52:15 2011 -0400 @@ -8,6 +8,7 @@ $ xt Sample two. $ xt Sample three. $ xt Sample four. + $ xt 'this | that' Finish and test .test.done: @@ -29,4 +30,11 @@ Sample one. | id:329950673481cb1c19102c982bfc63e745ab4a6f Sample two. | id:7a4dc18c23f3b890602da09da1690ccfb4c87bd1 Sample three. | id:90cf0626ca134e0aa6453b3562dc1c8bb34f1568 + $ xt -f 4 + $ cat .test.done + Sample four. | id:1dd56b09a9ca0fdf4f2a8c0959a298098eb8f7de + Sample one. | id:329950673481cb1c19102c982bfc63e745ab4a6f + this | that | id:48ad7c827191fa3c896d13b47f618ff1732e911e + Sample two. | id:7a4dc18c23f3b890602da09da1690ccfb4c87bd1 + Sample three. | id:90cf0626ca134e0aa6453b3562dc1c8bb34f1568