From 0e23f222b9cb79a40e2c02c4c714c44baef91b44 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 May 2016 00:10:12 -0400 Subject: [PATCH] CmdClear: Propagated cli, rules, database --- src/commands/CmdClear.cpp | 22 ++++++++++++++-------- src/commands/commands.h | 2 +- src/init.cpp | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/commands/CmdClear.cpp b/src/commands/CmdClear.cpp index 8625b125..5e2362e9 100644 --- a/src/commands/CmdClear.cpp +++ b/src/commands/CmdClear.cpp @@ -25,19 +25,25 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include //////////////////////////////////////////////////////////////////////////////// -int CmdClear () +int CmdClear ( + const CLI& cli, + Rules& rules, + Database& database) { - std::cout << "[clear: allows removal of tags form intervals]\n"; + auto filter = getFilter (cli); + if (! filter.range.started () && + filter.tags ().size () == 0) + throw std::string ("The 'clear' command refuses to delete all your data."); - // TODO Parse interval. - // TODO Parser tags. - // TODO Load all data. - // TODO Apply filter. - // TODO For each interval. - // TODO Remove tags. + auto tracked = getTrackedIntervals (database, rules, filter); + auto extent = outerRange (tracked); + + for (auto& interval : subset (extent, tracked)) + std::cout << "# clear impacts " << interval.dump () << "\n"; return 0; } diff --git a/src/commands/commands.h b/src/commands/commands.h index 68b10e6f..3f598762 100644 --- a/src/commands/commands.h +++ b/src/commands/commands.h @@ -33,7 +33,7 @@ #include int CmdCancel ( Rules&, Database& ); -int CmdClear ( ); +int CmdClear (const CLI&, Rules&, Database& ); int CmdConfig (const CLI&, Rules& ); int CmdContinue ( Rules&, Database& ); int CmdDefault ( Rules&, Database& ); diff --git a/src/init.cpp b/src/init.cpp index 7a1b90af..f6c8ced7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -227,7 +227,7 @@ int dispatchCommand ( // These signatures are æxpected to be all different, therefore no // command to fn mapping. if (command == "cancel") status = CmdCancel ( rules, database ); - else if (command == "clear") status = CmdClear ( ); + else if (command == "clear") status = CmdClear (cli, rules, database ); else if (command == "config") status = CmdConfig (cli, rules ); else if (command == "continue") status = CmdContinue ( rules, database ); else if (command == "day") status = CmdReportDay (cli, rules, database );