mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
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.
This commit is contained in:
parent
80fe5e4221
commit
145af6603c
2 changed files with 19 additions and 0 deletions
|
@ -50,11 +50,17 @@ int CmdStop (
|
|||
// Load the most recent interval.
|
||||
auto filter = getFilter (cli);
|
||||
auto latest = getLatestInterval (database);
|
||||
std::set <int> 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};
|
||||
|
|
13
test/stop.t
13
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue