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

Show which todo IDs are incorrect for 'pri'.

parent 43163f4f
...@@ -31,39 +31,44 @@ class PriorityCommand(Command): ...@@ -31,39 +31,44 @@ class PriorityCommand(Command):
if not super(PriorityCommand, self).execute(): if not super(PriorityCommand, self).execute():
return False return False
numbers = None
priority = None priority = None
try: todos = []
numbers = self.args[:-1] invalid_numbers = []
priority = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist)) for number in self.args[:-1]:
try:
todos.append(self.todolist.todo(number))
except InvalidTodoException:
invalid_numbers.append(number)
if len(numbers) > 0: if len(invalid_numbers) > 1 or len(invalid_numbers) > 0 and len(todos) > 0:
todos = [self.todolist.todo(number) for number in numbers] for number in invalid_numbers:
self.error("Invalid todo number given: {}.".format(number))
elif len(invalid_numbers) == 1 and len(todos) == 0:
self.error("Invalid todo number given.")
else:
try:
priority = self.args[-1]
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
if is_valid_priority(priority): if len(todos) > 0:
for todo in todos: if is_valid_priority(priority):
old_priority = todo.priority() for todo in todos:
self.todolist.set_priority(todo, priority) old_priority = todo.priority()
self.todolist.set_priority(todo, priority)
if old_priority and priority and old_priority != priority: if old_priority and priority and old_priority != priority:
self.out("Priority changed from {} to {}".format( self.out("Priority changed from {} to {}".format(
old_priority, priority)) old_priority, priority))
elif not old_priority: elif not old_priority:
self.out("Priority set to {}.".format(priority)) self.out("Priority set to {}.".format(priority))
self.out(self.printer.print_todo(todo)) self.out(self.printer.print_todo(todo))
else:
self.error("Invalid priority given.")
else: else:
self.error("Invalid priority given.") self.error(self.usage())
else: except (IndexError, InvalidCommandArgument):
self.error(self.usage())
except (IndexError, InvalidCommandArgument):
self.error(self.usage())
except (InvalidTodoException):
if len(numbers) > 0 and priority:
self.error( "Invalid todo number given.")
else:
self.error(self.usage()) self.error(self.usage())
def usage(self): def usage(self):
......
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