mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Refactor code as suggested and add tests.
This commit is contained in:
parent
f3280966e0
commit
3def4b10c4
2 changed files with 46 additions and 25 deletions
|
@ -41,7 +41,7 @@ int CmdContinue (
|
|||
|
||||
// Gather IDs and TAGs.
|
||||
std::set <int> ids = cli.getIds();
|
||||
auto tags = cli.getTags();
|
||||
auto filter = getFilter (cli);
|
||||
|
||||
if (ids.size() > 1)
|
||||
{
|
||||
|
@ -66,33 +66,14 @@ int CmdContinue (
|
|||
assert (intervals.size () == 1);
|
||||
to_copy = intervals.front ();
|
||||
}
|
||||
else if (!tags.empty())
|
||||
else if (!filter.tags().empty())
|
||||
{
|
||||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
for (int i = tracked.size() -1; i >= 0; --i)
|
||||
{
|
||||
bool allTagsFound = true;
|
||||
for (unsigned int t = 0; t < tags.size(); ++t)
|
||||
{
|
||||
if (!tracked[i].hasTag(tags[t]))
|
||||
{
|
||||
allTagsFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allTagsFound)
|
||||
{
|
||||
to_copy = tracked[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tracked.empty())
|
||||
throw format ("Tags '{1}' do not correspond to any tracking.", joinQuotedIfNeeded (", ", filter.tags()));
|
||||
|
||||
if (to_copy.empty())
|
||||
throw format ("Tags '{1}' do not correspond to any tracking.", joinQuotedIfNeeded (", ", tags));
|
||||
to_copy = tracked[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -111,7 +92,6 @@ int CmdContinue (
|
|||
to_copy = latest;
|
||||
}
|
||||
|
||||
auto filter = cli.getFilter ();
|
||||
Datetime start_time;
|
||||
Datetime end_time;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue