mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
CmdDelete: Implemented
This commit is contained in:
parent
8f55b49938
commit
c7c2496835
2 changed files with 29 additions and 7 deletions
|
@ -16,6 +16,8 @@
|
||||||
(thanks to Aaron Curtis).
|
(thanks to Aaron Curtis).
|
||||||
- TI-17 ids of tracked activities should not change when editing
|
- TI-17 ids of tracked activities should not change when editing
|
||||||
(thanks to lumbric).
|
(thanks to lumbric).
|
||||||
|
- TI-18 Add remove/delete command
|
||||||
|
(thanks to lumbric).
|
||||||
- TI-20 Week number does not agree with Taskwarrior
|
- TI-20 Week number does not agree with Taskwarrior
|
||||||
(thanks to Dirk Deimeke).
|
(thanks to Dirk Deimeke).
|
||||||
- TI-22 The 'day' chart crashes if there is an open interval and no others
|
- TI-22 The 'day' chart crashes if there is an open interval and no others
|
||||||
|
|
|
@ -34,16 +34,36 @@ int CmdDelete (
|
||||||
Rules& rules,
|
Rules& rules,
|
||||||
Database& database)
|
Database& database)
|
||||||
{
|
{
|
||||||
auto filter = getFilter (cli);
|
// Gather IDs and TAGs.
|
||||||
if (! filter.range.is_started () &&
|
std::vector <int> ids;
|
||||||
filter.tags ().size () == 0)
|
std::string delta;
|
||||||
throw std::string ("The 'delete' command refuses to delete all your data.");
|
for (auto& arg : cli._args)
|
||||||
|
if (arg.hasTag ("ID"))
|
||||||
|
ids.push_back (strtol (arg.attribute ("value").c_str (), NULL, 10));
|
||||||
|
|
||||||
|
if (! ids.size ())
|
||||||
|
throw std::string ("IDs must be specified. See 'timew help delete'.");
|
||||||
|
|
||||||
|
// TODO Support :adjust
|
||||||
|
|
||||||
|
// Load the data.
|
||||||
|
// Note: There is no filter.
|
||||||
|
Interval filter;
|
||||||
auto tracked = getTracked (database, rules, filter);
|
auto tracked = getTracked (database, rules, filter);
|
||||||
auto extent = outerRange (tracked);
|
|
||||||
|
|
||||||
for (auto& interval : subset (extent, tracked))
|
// Apply tags to ids.
|
||||||
std::cout << "# delete impacts " << interval.dump () << "\n";
|
for (auto& id : ids)
|
||||||
|
{
|
||||||
|
if (id <= static_cast <int> (tracked.size ()))
|
||||||
|
{
|
||||||
|
// Note: It's okay to subtract a one-based number from a zero-based index.
|
||||||
|
database.deleteInterval (tracked[tracked.size () - id]);
|
||||||
|
|
||||||
|
// Feedback.
|
||||||
|
if (rules.getBoolean ("verbose"))
|
||||||
|
std::cout << "Deleted @" << id << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue