CmdPurge: Detect the failure mode of trying to purge non-deleted tasks

Prompted by the failure mode described by Glen Solsberry in #2254.
This commit is contained in:
Tomas Babej 2020-11-26 23:48:56 -05:00 committed by Paul Beckingham
parent e37d932208
commit d43fa66489

View file

@ -135,6 +135,7 @@ int CmdPurge::execute (std::string&)
{
int rc = 0;
int count = 0;
bool matched_deleted = false;
Filter filter;
std::vector <Task> filtered;
@ -156,6 +157,9 @@ int CmdPurge::execute (std::string&)
// mark tasks as deleted before purging.
if (task.getStatus () == Task::deleted)
{
// Mark that at least one deleted task matched the filter
matched_deleted = true;
std::string question;
question = format ("Permanently remove task {1} '{2}'?",
task.identifier (true),
@ -166,6 +170,9 @@ int CmdPurge::execute (std::string&)
}
}
if (filtered.size () > 0 and ! matched_deleted)
Context::getContext ().footnote ("No deleted tasks specified. Maybe you forgot to delete tasks first?");
feedback_affected (count == 1 ? "Purged {1} task." : "Purged {1} tasks.", count);
return rc;
}