Commit ac61e8e6 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add --force flag to delete and do commands.

parent f8fe1f97
......@@ -64,6 +64,15 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertEquals(self.errors, "")
def test_del4(self):
command = DeleteCommand.DeleteCommand(["--force", "1"], self.todolist, self.out, self.error, lambda p: "y")
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEquals(self.todolist.count(), 1) # force won't delete subtasks
self.assertEquals(self.output, " 2 Bar p:1\nRemoved: Foo id:1\n")
self.assertEquals(self.errors, "")
def test_del5(self):
command = DeleteCommand.DeleteCommand(["2"], self.todolist, self.out, self.error)
command.execute()
......@@ -72,7 +81,7 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "Removed: Bar p:1\nThe following todo item(s) became active:\nFoo\n")
self.assertEquals(self.errors, "")
def test_del5(self):
def test_del7(self):
command = DeleteCommand.DeleteCommand(["99"], self.todolist, self.out, self.error)
command.execute()
......@@ -80,7 +89,7 @@ class DeleteCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "Invalid todo number given.\n")
def test_del6(self):
def test_del8(self):
command = DeleteCommand.DeleteCommand(["A"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -30,14 +30,25 @@ class DCommand(Command):
p_prompt=lambda a: None):
super(DCommand, self).__init__(p_args, p_todolist, p_out, p_err, p_prompt)
self.force = False
self.process_flags()
self.length = len(self.todolist.todos()) # to determine newly activated todos
self.force = self.argument_shift("--force") or self.argument_shift("-f")
try:
self.todo = self.todolist.todo(self.argument(0))
except (InvalidCommandArgument, InvalidTodoException):
self.todo = None
def process_flags(self):
opts, args = self.getopt("f", ["force"])
for opt, value in opts:
if opt == "-f" or opt == "--force":
self.force = True
self.args = args
def _uncompleted_children(self, p_todo):
return sorted([t for t in self.todolist.children(p_todo) if not t.is_completed()])
......
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