Commit 0bca00a7 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Arguments that start with - are a negation.

parent 1f3269c5
......@@ -38,21 +38,39 @@ class ListCommand(Command.Command):
elif o == '-s':
self.sort_expression = a
return args
self.args = args
def _filters(self):
filters = []
def grep_filters():
for arg in self.args:
if len(arg) > 1 and arg[0] == '-':
# when a word starts with -, exclude it
grep = Filter.NegationFilter(Filter.GrepFilter(arg[1:]))
else:
grep = Filter.GrepFilter(arg)
filters.append(grep)
if not self.show_all:
filters.append(Filter.DependencyFilter(self.todolist))
filters.append(Filter.RelevanceFilter())
grep_filters()
filters.append(Filter.LimitFilter(Config.LIST_LIMIT))
return filters
def execute(self):
if not super(ListCommand, self).execute():
return False
args = self._process_flags()
self._process_flags()
sorter = Sorter.Sorter(self.sort_expression)
filters = [] if self.show_all else [Filter.DependencyFilter(self.todolist), Filter.RelevanceFilter()]
for arg in args:
filters.append(Filter.GrepFilter(arg))
filters.append(Filter.LimitFilter(Config.LIST_LIMIT))
filters = self._filters()
self.out(self.todolist.view(sorter, filters).pretty_print())
......
......@@ -71,14 +71,22 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.errors, "")
def test_list8(self):
command = ListCommand.ListCommand(["-y"], self.todolist, self.out, self.error)
command = ListCommand.ListCommand(["-project1"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.output, " 4 (C) Drink beer @ home\n 5 (C) 13 + 29 = 42\n 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_list9(self):
command = ListCommand.ListCommand(["-project1", "-Drink"], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, " 5 (C) 13 + 29 = 42\n 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_list10(self):
command = ListCommand.ListCommand(["text1", "2"], self.todolist, self.out, self.errors)
command.execute()
......
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