Commit 51e53587 authored by Jacek Sowiński's avatar Jacek Sowiński

'postpone' can now handle multiple todos

topydo will report which todo IDs ('numbers') were invalid if user
supplied more than one on command-line. Error for operation on single
todo ID are reported as usual (for consistency with other commands sake
and because I'm lazy and don't want to fix 2 tests :P).
parent a9f29074
...@@ -58,31 +58,49 @@ class PostponeCommand(Command): ...@@ -58,31 +58,49 @@ class PostponeCommand(Command):
self._process_flags() self._process_flags()
try: todos = []
todo = self.todolist.todo(self.argument(0)) invalid_numbers = []
pattern = self.argument(1) for number in self.args[:-1]:
try:
offset = _get_offset(todo) todos.append(self.todolist.todo(number))
new_due = relative_date_to_date(pattern, offset) except InvalidTodoException:
invalid_numbers.append(number)
if new_due:
if self.move_start_date and todo.has_tag(config().tag_start()): if len(invalid_numbers) > 0 and len(todos) > 0:
length = todo.length() for number in invalid_numbers:
new_start = new_due - timedelta(length) self.error("Invalid todo number given: {}.".format(number))
todo.set_tag(config().tag_start(), new_start.isoformat()) elif len(invalid_numbers) == 1 and len(todos) == 0:
self.error("Invalid todo number given.")
else:
todo.set_tag(config().tag_due(), new_due.isoformat()) try:
pattern = self.args[-1]
self.todolist.set_dirty()
self.printer.add_filter(PrettyPrinterNumbers(self.todolist)) self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
self.out(self.printer.print_todo(todo))
else:
self.error("Invalid date pattern given.")
except InvalidCommandArgument: if len(todos) > 0:
self.error(self.usage()) for todo in todos:
except (InvalidTodoException): offset = _get_offset(todo)
self.error("Invalid todo number given.") new_due = relative_date_to_date(pattern, offset)
if new_due:
if self.move_start_date and todo.has_tag(config().tag_start()):
length = todo.length()
new_start = new_due - timedelta(length)
todo.set_tag(config().tag_start(), new_start.isoformat())
todo.set_tag(config().tag_due(), new_due.isoformat())
self.todolist.set_dirty()
self.out(self.printer.print_todo(todo))
else:
self.error("Invalid date pattern given.")
break
else:
self.error(self.usage())
except (InvalidCommandArgument, IndexError):
self.error(self.usage())
def usage(self): def usage(self):
return "Synopsis: postpone [-s] <NUMBER> <PATTERN>" return "Synopsis: postpone [-s] <NUMBER> <PATTERN>"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment