#21 Add implicit @1 to command 'untag'

- Extend interval assertions
- Add interval assertions to tests for command 'tag'
- Add interval assertions to tests for command 'untag'
This commit is contained in:
Thomas Lauf 2018-05-13 15:28:18 +02:00 committed by lauft
parent c595132a9c
commit 10dfa64cfa
5 changed files with 184 additions and 64 deletions

View file

@ -103,7 +103,6 @@ int CmdTag (
//TODO validate (cli, rules, database, i);
database.modifyInterval (tracked[tracked.size () - id], i);
// Feedback.
if (rules.getBoolean ("verbose"))
{
std::cout << "Added " << joinQuotedIfNeeded (" ", tags) << " to @" << id << '\n';

View file

@ -39,15 +39,11 @@ int CmdUntag (
{
// Gather IDs and TAGs.
std::set <int> ids = cli.getIds ();
std::vector<std::string> tags = cli.getTags ();
if (ids.empty ())
throw std::string ("IDs must be specified. See 'timew help untag'.");
std::vector <std::string> tags;
for (auto& arg : cli._args)
if (tags.empty ())
{
if (arg.hasTag ("TAG"))
tags.push_back (arg.attribute ("raw"));
throw std::string ("At least one tag must be specified. See 'timew help untag'.");
}
// Load the data.
@ -78,7 +74,22 @@ int CmdUntag (
}
}
// Apply tags to ids.
if (ids.empty ())
{
if (tracked.empty ())
{
throw std::string ("There is no active time tracking.");
}
if (!tracked.back ().range.is_open ())
{
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
}
ids.insert (1);
}
// Remove tags from ids.
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))