From 145af6603c688309e36680506cfc1f3ab7b30bac Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Sat, 21 Dec 2019 16:00:08 -0600 Subject: [PATCH] Stop with id should suggest modify command Recently I was trying to stop an interval that I had left open over the weekend, but I had already started a new interval at the beginning of the week. The error I was received was "The end of a date range must be after the start." which was confusing to me. After a few moments I realized I should have been using the modify command. Now the stop command will suggest modify if someone attempts to use stop for this purpose. --- src/commands/CmdStop.cpp | 6 ++++++ test/stop.t | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index 26d83222..c86f671e 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -50,11 +50,17 @@ int CmdStop ( // Load the most recent interval. auto filter = getFilter (cli); auto latest = getLatestInterval (database); + std::set ids = cli.getIds (); // Verify the interval is open. if (! latest.is_open ()) throw std::string ("There is no active time tracking."); + // We either expect no ids, or we're operating on the most current. + if (! ids.empty ()) + throw std::string ("The stop command works on the most recent open interval. " + "Perhaps you want the modify command?."); + journal.startTransaction (); Interval modified {latest}; diff --git a/test/stop.t b/test/stop.t index 6633e820..4e67a5cb 100755 --- a/test/stop.t +++ b/test/stop.t @@ -198,6 +198,19 @@ class TestStop(TestCase): self.assertEqual(len(j), 1) self.assertClosedInterval(j[0]) + def test_stop_with_id(self): + """Stop does not work with with ids other than one""" + self.t("start 2h ago") + self.t("start 1h ago") + + code, out, err = self.t.runError("stop @1") + # If trying to stop an older interval, check that modify was suggested. + self.assertIn("modify", err) + + code, out, err = self.t.runError("stop @2") + # If trying to stop an older interval, check that modify was suggested. + self.assertIn("modify", err) + if __name__ == "__main__": from simpletap import TAPTestRunner