Commit 96cca8b6 authored by Jacek Sowiński's avatar Jacek Sowiński

Introduce MultiCommand.execute() and execute_multi_specific()

Commands operating on multiple todos will inherit common execute()
method from MultiCommand class, and part specific for each command will
be covered in execute_multi_specific()
parent 4218f1bb
...@@ -129,13 +129,7 @@ class DCommand(MultiCommand): ...@@ -129,13 +129,7 @@ class DCommand(MultiCommand):
""" """
pass pass
def execute(self): def execute_multi_specific(self):
if not super(DCommand, self).execute():
return False
todo_errors = self.catch_todo_errors()
if not todo_errors:
old_active = self._active_todos() old_active = self._active_todos()
for todo in self.todos: for todo in self.todos:
...@@ -147,6 +141,3 @@ class DCommand(MultiCommand): ...@@ -147,6 +141,3 @@ class DCommand(MultiCommand):
current_active = self._active_todos() current_active = self._active_todos()
self._print_unlocked_todos(old_active, current_active) self._print_unlocked_todos(old_active, current_active)
else:
for error in todo_errors:
self.error(error)
...@@ -40,7 +40,7 @@ class MultiCommand(Command): ...@@ -40,7 +40,7 @@ class MultiCommand(Command):
except InvalidTodoException: except InvalidTodoException:
self.invalid_numbers.append(number) self.invalid_numbers.append(number)
def catch_todo_errors(self): def _catch_todo_errors(self):
""" """
Returns None or list of error messages depending on number of valid todo Returns None or list of error messages depending on number of valid todo
objects and number of invalid todo IDs. objects and number of invalid todo IDs.
...@@ -62,3 +62,22 @@ class MultiCommand(Command): ...@@ -62,3 +62,22 @@ class MultiCommand(Command):
return errors return errors
else: else:
return None return None
def execute_multi_specific(self):
"""
Operations specific for particular command dealing with multiple todo
IDs.
"""
pass
def execute(self):
if not super(MultiCommand, self).execute():
return False
todo_errors = self._catch_todo_errors()
if not todo_errors:
self.execute_multi_specific()
else:
for error in todo_errors:
self.error(error)
...@@ -45,7 +45,7 @@ class PostponeCommand(MultiCommand): ...@@ -45,7 +45,7 @@ class PostponeCommand(MultiCommand):
self.args = args self.args = args
def execute(self): def execute_multi_specific(self):
def _get_offset(p_todo): def _get_offset(p_todo):
offset = p_todo.tag_value( offset = p_todo.tag_value(
config().tag_due(), date.today().isoformat()) config().tag_due(), date.today().isoformat())
...@@ -56,12 +56,6 @@ class PostponeCommand(MultiCommand): ...@@ -56,12 +56,6 @@ class PostponeCommand(MultiCommand):
return offset_date return offset_date
if not super(PostponeCommand, self).execute():
return False
todo_errors = self.catch_todo_errors()
if not todo_errors:
try: try:
pattern = self.args[-1] pattern = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist)) self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
...@@ -85,9 +79,6 @@ class PostponeCommand(MultiCommand): ...@@ -85,9 +79,6 @@ class PostponeCommand(MultiCommand):
break break
except (InvalidCommandArgument, IndexError): except (InvalidCommandArgument, IndexError):
self.error(self.usage()) self.error(self.usage())
else:
for error in todo_errors:
self.error(error)
def usage(self): def usage(self):
return "Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>" return "Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>"
......
...@@ -29,14 +29,9 @@ class PriorityCommand(MultiCommand): ...@@ -29,14 +29,9 @@ class PriorityCommand(MultiCommand):
self.get_todos(self.args[:-1]) self.get_todos(self.args[:-1])
def execute(self): def execute_multi_specific(self):
if not super(PriorityCommand, self).execute():
return False
priority = None priority = None
todo_errors = self.catch_todo_errors()
if not todo_errors:
try: try:
priority = self.args[-1] priority = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist)) self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
...@@ -57,9 +52,6 @@ class PriorityCommand(MultiCommand): ...@@ -57,9 +52,6 @@ class PriorityCommand(MultiCommand):
self.error("Invalid priority given.") self.error("Invalid priority given.")
except IndexError: except IndexError:
self.error(self.usage()) self.error(self.usage())
else:
for error in todo_errors:
self.error(error)
def usage(self): def usage(self):
return """Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>""" return """Synopsis: pri <NUMBER1> [<NUMBER2> ...] <PRIORITY>"""
......
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