Move validation for tag set up

- The given set of tags must be a subset of the latest interval's tag set (this includes the empty case)
- If not a subset, throw an error and show the first non-matching tag
- This also prevents the stop command from doing any work on the database
- Closes #280

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2020-08-19 14:39:32 +02:00
parent 5b1c77b8aa
commit 96aaa71eb4

View file

@ -76,6 +76,18 @@ int CmdStop (
throw std::string ("The end of a date range must be after the start.");
}
std::set <std::string> diff = {};
if(! std::includes(latest.tags ().begin (), latest.tags ().end (),
filter.tags ().begin (), filter.tags ().end ()))
{
std::set_difference(filter.tags ().begin (), filter.tags ().end (),
latest.tags ().begin (), latest.tags ().end (),
std::inserter(diff, diff.begin ()));
throw format ("The current interval does not have the '{1}' tag.", *diff.begin ());
}
journal.startTransaction ();
Interval modified {latest};