mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Allow continue by tag.
This commit is contained in:
parent
6db29f1df5
commit
f3280966e0
2 changed files with 81 additions and 0 deletions
|
@ -41,6 +41,7 @@ int CmdContinue (
|
|||
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds();
|
||||
auto tags = cli.getTags();
|
||||
|
||||
if (ids.size() > 1)
|
||||
{
|
||||
|
@ -65,6 +66,34 @@ int CmdContinue (
|
|||
assert (intervals.size () == 1);
|
||||
to_copy = intervals.front ();
|
||||
}
|
||||
else if (!tags.empty())
|
||||
{
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
for (int i = tracked.size() -1; i >= 0; --i)
|
||||
{
|
||||
bool allTagsFound = true;
|
||||
for (unsigned int t = 0; t < tags.size(); ++t)
|
||||
{
|
||||
if (!tracked[i].hasTag(tags[t]))
|
||||
{
|
||||
allTagsFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allTagsFound)
|
||||
{
|
||||
to_copy = tracked[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (to_copy.empty())
|
||||
throw format ("Tags '{1}' do not correspond to any tracking.", joinQuotedIfNeeded (", ", tags));
|
||||
}
|
||||
else
|
||||
{
|
||||
Interval latest = getLatestInterval (database);
|
||||
|
|
|
@ -109,6 +109,58 @@ class TestContinue(TestCase):
|
|||
self.assertIn("Recorded BAR\n", out)
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
def test_continue_with_multiple_tags(self):
|
||||
"""Verify that 'continue' with multiple tags works"""
|
||||
code, out, err = self.t("start FOO BAR 2h ago")
|
||||
self.assertIn("Tracking BAR FOO\n", out)
|
||||
|
||||
code, out, err = self.t("start BAR 1h ago")
|
||||
self.assertIn("Tracking BAR\n", out)
|
||||
|
||||
code, out, err = self.t("start FOO 30min ago")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
code, out, err = self.t("continue FOO BAR")
|
||||
self.assertIn("Recorded FOO\n", out)
|
||||
self.assertIn("Tracking BAR FOO\n", out)
|
||||
|
||||
def test_continue_with_invalid_tag(self):
|
||||
"""Verify that 'continue' with invalid tag is an error"""
|
||||
code, out, err = self.t("start FOO 1h ago")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
code, out, err = self.t("stop 30min ago")
|
||||
self.assertIn("Recorded FOO\n", out)
|
||||
|
||||
code, out, err = self.t.runError("continue BAR")
|
||||
self.assertIn("Tags 'BAR' do not correspond to any tracking.\n", err)
|
||||
|
||||
def test_continue_with_tag_without_active_tracking(self):
|
||||
"""Verify that continuing a specified interval works"""
|
||||
code, out, err = self.t("start FOO 1h ago")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
code, out, err = self.t("start BAR 30min ago")
|
||||
self.assertIn("Tracking BAR\n", out)
|
||||
|
||||
code, out, err = self.t("stop 15min ago")
|
||||
self.assertIn("Recorded BAR\n", out)
|
||||
|
||||
code, out, err = self.t("continue FOO")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
def test_continue_with_tag_with_active_tracking(self):
|
||||
"""Verify that continuing a specified interval stops active tracking"""
|
||||
code, out, err = self.t("start FOO 1h ago")
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
code, out, err = self.t("start BAR 30min ago")
|
||||
self.assertIn("Tracking BAR\n", out)
|
||||
|
||||
code, out, err = self.t("continue FOO")
|
||||
self.assertIn("Recorded BAR\n", out)
|
||||
self.assertIn("Tracking FOO\n", out)
|
||||
|
||||
def test_continue_with_id_and_date(self):
|
||||
"""Verify that continuing a specified interval with date continues at given date"""
|
||||
now_utc = datetime.now().utcnow()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue