From e6b5a14927dbf01cf1d8d024951cea6b1927b3c7 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Sat, 24 Aug 2019 23:56:33 +0200 Subject: [PATCH] Extend command 'annotate' to remove annotation - Closes #247 Signed-off-by: Thomas Lauf --- ChangeLog | 1 + src/commands/CmdAnnotate.cpp | 14 ++++++++------ test/annotate.t | 11 +++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 55a0b2b5..14aa8896 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,6 +57,7 @@ (thanks to RainbowSwirls) - #240 Core dump when specifying a start time in the past (thanks to OddBloke) +- #247 Remove annotation from interval - Fixed error from totals.py while timer is active (thanks to davisdude) - Refactoring of Interval and Range diff --git a/src/commands/CmdAnnotate.cpp b/src/commands/CmdAnnotate.cpp index 874d9405..82435dae 100644 --- a/src/commands/CmdAnnotate.cpp +++ b/src/commands/CmdAnnotate.cpp @@ -41,11 +41,6 @@ int CmdAnnotate ( std::set ids = cli.getIds (); std::string annotation = cli.getAnnotation (); - if (annotation.empty ()) - { - throw std::string ("No annotation string given. See 'timew help annotate'."); - } - // Load the data. // Note: There is no filter. Interval filter; @@ -108,7 +103,14 @@ int CmdAnnotate ( if (rules.getBoolean ("verbose")) { - std::cout << "Annotated @" << id << " with \"" << annotation << "\"" << std::endl; + if (annotation.empty ()) + { + std::cout << "Removed annotation from @" << id << std::endl; + } + else + { + std::cout << "Annotated @" << id << " with \"" << annotation << "\"" << std::endl; + } } } diff --git a/test/annotate.t b/test/annotate.t index 349ff1d4..9d97db07 100755 --- a/test/annotate.t +++ b/test/annotate.t @@ -91,16 +91,19 @@ class TestAnnotate(TestCase): self.assertIn("At least one ID must be specified.", err) - def test_should_fail_on_no_annotation(self): - """Calling command 'annotate' without annotation is an error""" + def test_remove_annotation_from_interval(self): + """Calling 'annotate' without annotation removes annotation""" now_utc = datetime.now().utcnow() one_hour_before_utc = now_utc - timedelta(hours=1) self.t("track {:%Y-%m-%dT%H:%M:%S}Z - {:%Y-%m-%dT%H:%M:%S}Z".format(one_hour_before_utc, now_utc)) - code, out, err = self.t.runError("annotate @1") + code, out, err = self.t("annotate @1") - self.assertIn("No annotation string given.", err) + self.assertIn("Removed annotation from @1", out) + + j = self.t.export() + self.assertClosedInterval(j[0], expectedAnnotation="") def test_add_annotation_to_closed_interval(self): """Add an annotation to a closed interval"""