Skip to content

Commit 50e48dd

Browse files
committed
Add command to delete tasks.
1 parent abc4d9a commit 50e48dd

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/application_business_rules/serial_interface/Protocol.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace cli = command_line_interpreter;
99
// --- define commands ------
1010
// --------------------------
1111
#include "JsonGenerator.hpp"
12+
#include <serial_protocol/DeletedTaskObject.hpp>
1213
#include <serial_protocol/ProtocolVersionObject.hpp>
1314
#include <serial_protocol/TaskList.hpp>
1415
#include <serial_protocol/TaskObject.hpp>
@@ -70,7 +71,19 @@ static const auto add = [](const TaskId id, const std::basic_string<ProtocolHand
7071
};
7172
static const auto addCmd = cli::makeCommand("add", std::function(add), std::make_tuple(&id, &label, &duration));
7273

73-
static const std::array<const cli::BaseCommand<char> *, 4> commands = {&listCmd, &editCmd, &infoCmd, &addCmd};
74+
// command for delete/remove
75+
static const auto del = [](const TaskId id) {
76+
const bool deleted = device::tasks.erase(id) > 0;
77+
const DeletedTaskObject taskObject{.id = id};
78+
serial_port::cout << toJsonString(taskObject) << std::endl;
79+
if (!deleted)
80+
{
81+
serial_port::cout << "ERROR: No task deleted." << std::endl;
82+
}
83+
};
84+
static const auto delCmd = cli::makeCommand("delete", std::function(del), std::make_tuple(&id));
85+
86+
static const std::array<const cli::BaseCommand<char> *, 5> commands = {&listCmd, &editCmd, &infoCmd, &addCmd, &delCmd};
7487

7588
bool ProtocolHandler::execute(const CharType *const commandLine)
7689
{

0 commit comments

Comments
 (0)