@@ -8,22 +8,41 @@ namespace cli = command_line_interpreter;
88// --------------------------
99// --- define commands ------
1010// --------------------------
11+ #include " JsonGenerator.hpp"
12+ #include < serial_protocol/ProtocolVersionObject.hpp>
13+ #include < serial_protocol/TaskList.hpp>
14+ #include < serial_protocol/TaskObject.hpp>
1115#include < string>
1216
17+ using namespace task_tracker_systems ;
18+
19+ // command for info
20+ static const auto info = []() {
21+ constexpr ProtocolVersionObject version = {.major = 0 , .minor = 1 , .patch = 0 };
22+ serial_port::cout << toJsonString (version) << std::endl;
23+ };
24+ static const auto infoCmd = cli::makeCommand(" info" , std::function(info));
25+
1326// command for list
14- static const auto list = []() { serial_port::cout << " this is a list: a, b, c, ..." << std::endl; };
27+ static const auto list = []() {
28+ const TaskList dummyList = {
29+ {.id = 1 , .label = " first" , .duration = 100U },
30+ {.id = 2 , .label = " second" , .duration = 200U },
31+ };
32+ serial_port::cout << toJsonString (dummyList) << std::endl; };
1533static const auto listCmd = cli::makeCommand(" list" , std::function(list));
1634
1735// command for edit
18- static const auto edit = [](const int id, const std::basic_string<ProtocolHandler::CharType> label, const int duration) {
19- serial_port::cout << " Edit id(" << id << " ) label('" << label << " ') duration(" << duration << " )" << std::endl;
36+ static const auto edit = [](const unsigned int id, const std::basic_string<ProtocolHandler::CharType> label, const std::chrono::seconds::rep duration) {
37+ const TaskObject task = {.id = id, .label = label, .duration = duration};
38+ serial_port::cout << toJsonString (task) << std::endl;
2039};
21- static const cli::Option<int > id = {.labels = {" --id" }, .defaultValue = 0 };
40+ static const cli::Option<unsigned int > id = {.labels = {" --id" }, .defaultValue = 0 };
2241static const cli::Option<std::basic_string<ProtocolHandler::CharType>> label = {.labels = {" --name" }, .defaultValue = " foo" };
23- static const cli::Option<int > duration = {.labels = {" --duration" }, .defaultValue = 0 };
42+ static const cli::Option<std::chrono::seconds::rep > duration = {.labels = {" --duration" }, .defaultValue = 0 };
2443static const auto editCmd = cli::makeCommand(" edit" , std::function(edit), std::make_tuple(&id, &label, &duration));
2544
26- static const std::array<const cli::BaseCommand<char > *, 2 > commands = {&listCmd, &editCmd};
45+ static const std::array<const cli::BaseCommand<char > *, 3 > commands = {&listCmd, &editCmd, &infoCmd };
2746
2847bool ProtocolHandler::execute (const CharType *const commandLine)
2948{
0 commit comments