diff --git a/src/commands/CmdTag.cpp b/src/commands/CmdTag.cpp index eb056fa7..89e48fc7 100644 --- a/src/commands/CmdTag.cpp +++ b/src/commands/CmdTag.cpp @@ -39,12 +39,6 @@ int CmdTag ( { // Gather IDs and TAGs. std::set ids = cli.getIds (); - - if (ids.empty ()) - { - throw std::string ("IDs must be specified. See 'timew help tag'."); - } - std::vector tags = cli.getTags (); // Load the data. @@ -75,6 +69,11 @@ int CmdTag ( } } + if (ids.empty ()) + { + throw std::string ("At least one ID must be specified. See 'timew help tag'."); + } + // Apply tags to ids. for (auto& id : ids) { diff --git a/test/tag.t b/test/tag.t index a8eebf3b..814b8866 100755 --- a/test/tag.t +++ b/test/tag.t @@ -49,6 +49,13 @@ class TestTag(TestCase): code, out, err = self.t("tag @1 foo") self.assertIn('Added foo to @1', out) + + def test_should_fail_on_missing_id_and_inactive_time_tracking(self): + """Missing id on inactive time tracking is an error""" + self.t("track yesterday for 1hour") + code, out, err = self.t.runError("tag foo") + self.assertIn("At least one ID must be specified.", err) + def test_add_tag_to_closed_interval(self): """Add a tag to an closed interval""" self.t("track yesterday for 1hour")