Commit aae4efa7 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Throw exception when an argument could not be found.

parent 3c7ef04b
import Command
from Command import *
from PrettyPrinter import pretty_print
import TodoList
from Utils import convert_todo_number, InvalidTodoNumberException
class AppendCommand(Command.Command):
class AppendCommand(Command):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
p_err=lambda a: None,
......@@ -11,10 +11,8 @@ class AppendCommand(Command.Command):
super(AppendCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt=lambda a: None)
def execute(self):
number = self.argument(0)
if number:
try:
number = convert_todo_number(number)
number = convert_todo_number(self.argument(0))
text = " ".join(self.args[1:])
if text:
......@@ -23,7 +21,7 @@ class AppendCommand(Command.Command):
self.out(pretty_print(todo, [self.todolist.pp_number()]))
else:
self.error(self.usage())
except InvalidTodoNumberException:
except (InvalidCommandArgument, InvalidTodoNumberException):
self.error(self.usage())
except TodoList.InvalidTodoException:
self.error("Invalid todo number given.")
......
class InvalidCommandArgument(Exception):
pass
class Command(object):
def __init__(self, p_args, p_todolist,
p_out=lambda a: None,
......@@ -37,13 +40,13 @@ class Command(object):
"""
return False
def argument(self, p_number):
def argument(self, p_number, p_error=None):
""" Retrieves a value from the argument list at the given position. """
value = None
try:
value = self.args[p_number]
except IndexError:
self.error(self.usage())
raise InvalidCommandArgument
return value
......
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