CmdDelete: Added @id range error

This commit is contained in:
Paul Beckingham 2016-07-24 10:30:32 -04:00
parent 0f4d5ec9a3
commit 96f3d6f391

View file

@ -26,6 +26,7 @@
#include <cmake.h> #include <cmake.h>
#include <timew.h> #include <timew.h>
#include <format.h>
#include <iostream> #include <iostream>
#include <stdlib.h> #include <stdlib.h>
@ -35,9 +36,8 @@ int CmdDelete (
Rules& rules, Rules& rules,
Database& database) Database& database)
{ {
// Gather IDs and TAGs. // Gather IDs.
std::vector <int> ids; std::vector <int> ids;
std::string delta;
for (auto& arg : cli._args) for (auto& arg : cli._args)
if (arg.hasTag ("ID")) if (arg.hasTag ("ID"))
ids.push_back (strtol (arg.attribute ("value").c_str (), NULL, 10)); ids.push_back (strtol (arg.attribute ("value").c_str (), NULL, 10));
@ -45,8 +45,6 @@ int CmdDelete (
if (! ids.size ()) if (! ids.size ())
throw std::string ("IDs must be specified. See 'timew help delete'."); throw std::string ("IDs must be specified. See 'timew help delete'.");
// TODO Support :adjust
// Load the data. // Load the data.
// Note: There is no filter. // Note: There is no filter.
Interval filter; Interval filter;
@ -55,16 +53,15 @@ int CmdDelete (
// Apply tags to ids. // Apply tags to ids.
for (auto& id : ids) for (auto& id : ids)
{ {
if (id <= static_cast <int> (tracked.size ())) if (id > static_cast <int> (tracked.size ()))
{ throw format ("ID '@{1}' does not correspond to any tracking.", id);
// Note: It's okay to subtract a one-based number from a zero-based index. // Note: It's okay to subtract a one-based number from a zero-based index.
database.deleteInterval (tracked[tracked.size () - id]); database.deleteInterval (tracked[tracked.size () - id]);
// Feedback.
if (rules.getBoolean ("verbose")) if (rules.getBoolean ("verbose"))
std::cout << "Deleted @" << id << '\n'; std::cout << "Deleted @" << id << '\n';
} }
}
return 0; return 0;
} }