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):
"""
pass
def execute(self):
if not super(DCommand, self).execute():
return False
todo_errors = self.catch_todo_errors()
if not todo_errors:
def execute_multi_specific(self):
old_active = self._active_todos()
for todo in self.todos:
......@@ -147,6 +141,3 @@ class DCommand(MultiCommand):
current_active = self._active_todos()
self._print_unlocked_todos(old_active, current_active)
else:
for error in todo_errors:
self.error(error)
......@@ -40,7 +40,7 @@ class MultiCommand(Command):
except InvalidTodoException:
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
objects and number of invalid todo IDs.
......@@ -62,3 +62,22 @@ class MultiCommand(Command):
return errors
else:
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):
self.args = args
def execute(self):
def execute_multi_specific(self):
def _get_offset(p_todo):
offset = p_todo.tag_value(
config().tag_due(), date.today().isoformat())
......@@ -56,12 +56,6 @@ class PostponeCommand(MultiCommand):
return offset_date
if not super(PostponeCommand, self).execute():
return False
todo_errors = self.catch_todo_errors()
if not todo_errors:
try:
pattern = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
......@@ -85,9 +79,6 @@ class PostponeCommand(MultiCommand):
break
except (InvalidCommandArgument, IndexError):
self.error(self.usage())
else:
for error in todo_errors:
self.error(error)
def usage(self):
return "Synopsis: postpone [-s] <NUMBER> [<NUMBER2> ...] <PATTERN>"
......
......@@ -29,14 +29,9 @@ class PriorityCommand(MultiCommand):
self.get_todos(self.args[:-1])
def execute(self):
if not super(PriorityCommand, self).execute():
return False
def execute_multi_specific(self):
priority = None
todo_errors = self.catch_todo_errors()
if not todo_errors:
try:
priority = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
......@@ -57,9 +52,6 @@ class PriorityCommand(MultiCommand):
self.error("Invalid priority given.")
except IndexError:
self.error(self.usage())
else:
for error in todo_errors:
self.error(error)
def usage(self):
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