-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.cpp
40 lines (27 loc) · 1.26 KB
/
commands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <string>
#include <iostream>
#include <map>
#include <functional>
#include <vector>
std::string joinvectorintostring(const std::vector<std::string>& elements, const std::string& delimiter) {
std::ostringstream result;
for (size_t i = 0; i < elements.size(); ++i) {
result << elements[i];
if (i < elements.size() - 1) {
result << delimiter; // Add delimiter between elements, but not after the last element
}
}
return result.str();
}
void echo(const std::vector<std::string>& Arguments) {
std::cout << joinvectorintostring(Arguments, " ") << std::endl;
}
void time(const std::vector<std::string>& Arguments) {
std::cout << "It is: " << TimeUtils::todayDate("D/M/Y") << " at " << TimeUtils::secondAccuracy() << std::endl;
std::cout << "Using date format: DD/MM/YYYY." << std::endl;
}
std::map<std::string,std::function<void(const std::vector<std::string>&)>> AllCommands = {
{"echo", std::function<void(const std::vector<std::string>&)>(echo)},
{"time", std::function<void(const std::vector<std::string>&)>(static_cast<void(*)(const std::vector<std::string>&)>(time))},
{"date", std::function<void(const std::vector<std::string>&)>(static_cast<void(*)(const std::vector<std::string>&)>(time))}
};