Commit 91dcd57b authored by Bram Schoenmakers's avatar Bram Schoenmakers

Pass arguments to the command.

parent cb26e769
...@@ -6,9 +6,9 @@ import Command ...@@ -6,9 +6,9 @@ import Command
from RelativeDate import relative_date_to_date from RelativeDate import relative_date_to_date
class AddCommand(Command.Command): class AddCommand(Command.Command):
def __init__(self, p_text, p_todolist): def __init__(self, p_args, p_todolist):
super(AddCommand, self).__init__(p_todolist) super(AddCommand, self).__init__(p_args, p_todolist)
self.text = p_text self.text = ' '.join(p_args)
def _preprocess_input_todo(self): def _preprocess_input_todo(self):
""" """
...@@ -62,3 +62,5 @@ class AddCommand(Command.Command): ...@@ -62,3 +62,5 @@ class AddCommand(Command.Command):
self.todo = self.todolist.add(self.text) self.todo = self.todolist.add(self.text)
self._postprocess_input_todo() self._postprocess_input_todo()
return True
class Command(object): class Command(object):
def __init__(self, p_todolist): def __init__(self, p_args, p_todolist):
self.args = p_args
self.todolist = p_todolist self.todolist = p_todolist
def execute(self): def execute(self):
""" The command to execute. """ """ The command to execute. """
pass return False
...@@ -39,6 +39,18 @@ def argument(p_number): ...@@ -39,6 +39,18 @@ def argument(p_number):
return value return value
def arguments():
"""
Retrieves all values from the argument list starting from the given
position.
"""
try:
values = sys.argv[2:] # strip off subcommand at position 1
except IndexError:
usage()
return values
def convert_number(p_number): def convert_number(p_number):
""" Converts a string number to an integer. """ """ Converts a string number to an integer. """
try: try:
...@@ -60,8 +72,8 @@ class Application(object): # TODO: rename to CLIApplication ...@@ -60,8 +72,8 @@ class Application(object): # TODO: rename to CLIApplication
print printed[0] print printed[0]
def add(self): def add(self):
command = AddCommand(argument(2), self.todolist) command = AddCommand(arguments(), self.todolist)
command.execute() if command.execute():
self.print_todo(self.todolist.count()) self.print_todo(self.todolist.count())
self.dirty = True self.dirty = True
......
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