Commit 9fdbde19 authored by Bram Schoenmakers's avatar Bram Schoenmakers Committed by GitHub

Merge pull request #169 from mruwek/before-after-dep-ls

Introduce 'before' and 'after' keywords to `dep ls`
parents edc11eeb 67975f4b
...@@ -271,6 +271,42 @@ class DepCommandTest(CommandTest): ...@@ -271,6 +271,42 @@ class DepCommandTest(CommandTest):
self.assertEqual(self.errors, "Invalid todo number given.\n") self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_ls5(self): def test_ls5(self):
command = DepCommand(["ls", "before", "1"], self.todolist, self.out,
self.error)
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 2| Bar p:1\n| 3| Baz p:1\n")
self.assertEqual(self.errors, "")
def test_ls6(self):
command = DepCommand(["ls", "before", "99"], self.todolist, self.out,
self.error)
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_ls7(self):
command = DepCommand(["ls", "after", "3"], self.todolist, self.out,
self.error)
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "| 1| Foo id:1\n")
self.assertEqual(self.errors, "")
def test_ls8(self):
command = DepCommand(["ls", "after", "99"], self.todolist, self.out,
self.error)
command.execute()
self.assertFalse(self.todolist.dirty)
self.assertEqual(self.output, "")
self.assertEqual(self.errors, "Invalid todo number given.\n")
def test_ls9(self):
command = DepCommand(["ls", "1"], self.todolist, self.out, self.error) command = DepCommand(["ls", "1"], self.todolist, self.out, self.error)
command.execute() command.execute()
...@@ -278,7 +314,7 @@ class DepCommandTest(CommandTest): ...@@ -278,7 +314,7 @@ class DepCommandTest(CommandTest):
self.assertEqual(self.output, "") self.assertEqual(self.output, "")
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_ls6(self): def test_ls10(self):
command = DepCommand(["ls"], self.todolist, self.out, self.error) command = DepCommand(["ls"], self.todolist, self.out, self.error)
command.execute() command.execute()
...@@ -286,7 +322,7 @@ class DepCommandTest(CommandTest): ...@@ -286,7 +322,7 @@ class DepCommandTest(CommandTest):
self.assertFalse(self.output) self.assertFalse(self.output)
self.assertEqual(self.errors, command.usage() + "\n") self.assertEqual(self.errors, command.usage() + "\n")
def test_ls7(self): def test_ls11(self):
command = DepCommand(["ls", "top", "99"], self.todolist, self.out, command = DepCommand(["ls", "top", "99"], self.todolist, self.out,
self.error) self.error)
command.execute() command.execute()
......
...@@ -108,24 +108,23 @@ class DepCommand(Command): ...@@ -108,24 +108,23 @@ class DepCommand(Command):
arg2 = self.argument(2) arg2 = self.argument(2)
todos = [] todos = []
if arg2 == 'to': if arg2 == 'to' or arg1 == 'before':
# dep ls 1 to ... # dep ls 1 to OR dep ls before 1
number = arg1 number = arg1 if arg2 == 'to' else arg2
todo = self.todolist.todo(number) todo = self.todolist.todo(number)
todos = self.todolist.children(todo) todos = self.todolist.children(todo)
elif arg1 == 'to': elif arg1 in {'to', 'after'}:
# dep ls ... to 1 # dep ls to 1 OR dep ls after 1
number = arg2 number = arg2
todo = self.todolist.todo(number) todo = self.todolist.todo(number)
todos = self.todolist.parents(todo) todos = self.todolist.parents(todo)
else: else:
self.error(self.usage()) raise InvalidCommandArgument
if todos: sorter = Sorter(config().sort_string())
sorter = Sorter(config().sort_string()) instance_filter = Filter.InstanceFilter(todos)
instance_filter = Filter.InstanceFilter(todos) view = View(sorter, [instance_filter], self.todolist)
view = View(sorter, [instance_filter], self.todolist) self.out(self.printer.print_list(view.todos))
self.out(self.printer.print_list(view.todos))
except InvalidTodoException: except InvalidTodoException:
self.error("Invalid todo number given.") self.error("Invalid todo number given.")
except InvalidCommandArgument: except InvalidCommandArgument:
...@@ -176,6 +175,7 @@ class DepCommand(Command): ...@@ -176,6 +175,7 @@ class DepCommand(Command):
dep add <NUMBER> <before|partof|after|parents-of|children-of> <NUMBER> dep add <NUMBER> <before|partof|after|parents-of|children-of> <NUMBER>
dep ls <NUMBER> to dep ls <NUMBER> to
dep ls to <NUMBER> dep ls to <NUMBER>
dep ls <before|after> <NUMBER>
dep dot <NUMBER> dep dot <NUMBER>
dep clean""" dep clean"""
......
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