mirror of
https://github.com/topydo/topydo.git
synced 2024-06-03 02:48:34 +00:00
Add -r flag to tag subcommand to enforce relative dates
Relative dates were already interpreted for due and start tags, but you can also enforce it for other tags by passing the -r flag to the tag command.
This commit is contained in:
parent
5e626f620a
commit
7ba9912cb8
|
@ -173,6 +173,35 @@ class TagCommandTest(CommandTest):
|
|||
self.assertEqual(self.output, "| 3| Baz due:2014-10-20 foo:today\n")
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
@freeze_time('2017, 1, 12')
|
||||
def test_set_tag13(self):
|
||||
"""
|
||||
Convert relative dates when forced to.
|
||||
"""
|
||||
|
||||
command = TagCommand(["-r", "3", "foo", "today"], self.todolist,
|
||||
self.out, self.error)
|
||||
|
||||
command.execute()
|
||||
|
||||
self.assertTrue(self.todolist.dirty)
|
||||
self.assertEqual(self.output, "| 3| Baz due:2014-10-20 foo:2017-01-12\n")
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
def test_set_tag14(self):
|
||||
"""
|
||||
Leave the original value when an invalid relative date was given.
|
||||
"""
|
||||
|
||||
command = TagCommand(["-r", "3", "foo", "bar"], self.todolist,
|
||||
self.out, self.error)
|
||||
|
||||
command.execute()
|
||||
|
||||
self.assertTrue(self.todolist.dirty)
|
||||
self.assertEqual(self.output, "| 3| Baz due:2014-10-20 foo:bar\n")
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
def test_rm_tag01(self):
|
||||
command = TagCommand(["1", "due"], self.todolist, self.out, self.error)
|
||||
command.execute()
|
||||
|
|
|
@ -31,6 +31,7 @@ class TagCommand(Command):
|
|||
|
||||
self.force = False
|
||||
self.force_add = False
|
||||
self.relative_date = False
|
||||
self.todo = None
|
||||
self.tag = None
|
||||
self.value = None
|
||||
|
@ -38,12 +39,14 @@ class TagCommand(Command):
|
|||
self.current_values = []
|
||||
|
||||
def _process_flags(self):
|
||||
flags, args = self.getopt("af")
|
||||
flags, args = self.getopt("afr")
|
||||
for flag, _ in flags:
|
||||
if flag == "-a":
|
||||
self.force_add = True
|
||||
elif flag == "-f":
|
||||
self.force = True
|
||||
elif flag == "-r":
|
||||
self.relative_date = True
|
||||
|
||||
self.args = args
|
||||
|
||||
|
@ -93,7 +96,10 @@ class TagCommand(Command):
|
|||
return answer
|
||||
|
||||
def _convert_relative_dates(self):
|
||||
if self.tag == config().tag_start() or self.tag == config().tag_due():
|
||||
is_start_tag = self.tag == config().tag_start()
|
||||
is_due_tag = self.tag == config().tag_due()
|
||||
|
||||
if self.relative_date or is_start_tag or is_due_tag:
|
||||
real_date = relative_date_to_date(self.value)
|
||||
|
||||
if real_date:
|
||||
|
@ -143,5 +149,7 @@ is omitted, the TAG is removed from the todo item.
|
|||
-a : Do not change the current value of the TAG if it exists, but add a new
|
||||
VALUE for the given TAG.
|
||||
-f : Force setting/removing all values of the TAG. Prevents interaction with
|
||||
the user.\
|
||||
the user.
|
||||
-r : Interpret the given value as a relative date and convert it to an absolute
|
||||
date.\
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue