Commit a15654e0 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Implement 'after', 'before' and 'partof' operators.

parent b0eab341
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -72,6 +72,34 @@ class DepCommandTest(CommandTest.CommandTest):
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, "")
self.assertEquals(self.errors, command.usage() + "\n")
def test_add6(self):
command = DepCommand.DepCommand(["add", "1", "after", "4"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(4).has_tag('p', '1'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
def test_add7(self):
command = DepCommand.DepCommand(["add", "1", "before", "4"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).has_tag('p', '2'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
def test_add8(self):
command = DepCommand.DepCommand(["add", "1", "partof", "4"], self.todolist, self.out, self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertTrue(self.todolist.todo(1).has_tag('p', '2'))
self.assertEquals(self.output, "")
self.assertEquals(self.errors, "")
def rm_helper(self, p_args):
"""
Helper function that checks the removal of the dependency from todo 1
......
......@@ -51,13 +51,19 @@ class DepCommand(Command):
to_todo = None
try:
from_todo_nr = convert_todo_number(self.argument(1))
to_todo_nr = self.argument(2)
operator = self.argument(2)
if to_todo_nr == 'to':
if operator == 'before' or operator == 'partof':
from_todo_nr = convert_todo_number(self.argument(3))
to_todo_nr = convert_todo_number(self.argument(1))
elif operator == 'to' or operator == 'after':
from_todo_nr = convert_todo_number(self.argument(1))
to_todo_nr = convert_todo_number(self.argument(3))
else:
to_todo_nr = convert_todo_number(to_todo_nr)
# the operator was omitted, assume 2nd argument is target task
# default to 'to' behavior
from_todo_nr = convert_todo_number(self.argument(1))
to_todo_nr = convert_todo_number(self.argument(2))
from_todo = self.todolist.todo(from_todo_nr)
to_todo = self.todolist.todo(to_todo_nr)
......@@ -119,12 +125,13 @@ class DepCommand(Command):
def usage(self):
return """Synopsis:
dep <add|rm> <NUMBER> [to] <NUMBER>
dep add <NUMBER> <before|partof|after> <NUMBER>
dep ls <NUMBER> to
dep ls to <NUMBER>
dep clean"""
def help(self):
return """* add: Adds a dependency.
return """* add: Adds a dependency. Using 1 before 2 creates a dependency from todo item 2 to 1.
* rm (alias: del): Removes a dependency.
* ls: Lists all dependencies to or from a certain todo.
* clean (alias: gc): Removes redundant id or p tags."""
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