Commit cd587fd6 authored by Jacek Sowiński's avatar Jacek Sowiński

Allow 'pri' to prioritize multiple todos at once.

Fixes issue #5
parent 2a9be13f
...@@ -30,14 +30,19 @@ class PriorityCommand(Command): ...@@ -30,14 +30,19 @@ class PriorityCommand(Command):
if not super(PriorityCommand, self).execute(): if not super(PriorityCommand, self).execute():
return False return False
number = None numbers = None
priority = None priority = None
try: try:
number = self.argument(0) numbers = self.args[:-1]
priority = self.argument(1) priority = self.args[-1]
todo = self.todolist.todo(number)
if len(numbers) > 0:
todos = []
for number in numbers:
todos.append(self.todolist.todo(number))
if is_valid_priority(priority): if is_valid_priority(priority):
for todo in todos:
old_priority = todo.priority() old_priority = todo.priority()
self.todolist.set_priority(todo, priority) self.todolist.set_priority(todo, priority)
...@@ -50,10 +55,14 @@ class PriorityCommand(Command): ...@@ -50,10 +55,14 @@ class PriorityCommand(Command):
self.out(self.printer.print_todo(todo)) self.out(self.printer.print_todo(todo))
else: else:
self.error("Invalid priority given.") self.error("Invalid priority given.")
else:
self.error(self.usage())
except IndexError:
self.error(self.usage())
except InvalidCommandArgument: except InvalidCommandArgument:
self.error(self.usage()) self.error(self.usage())
except (InvalidTodoException): except (InvalidTodoException):
if number and priority: if len(numbers) > 0 and priority:
self.error( "Invalid todo number given.") self.error( "Invalid todo number given.")
else: else:
self.error(self.usage()) self.error(self.usage())
......
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