- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_line_interface.cpp
More file actions
Latest commit
28 lines (24 loc) · 688 Bytes
/
Copy pathcommand_line_interface.cpp
File metadata and controls
28 lines (24 loc) · 688 Bytes
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
#include"command_line_interface.hpp"
#include<iostream>
voidCommandLineInterface::registerCommand(const std::string &command, std::function<void()> function) {
callbacks[command] = function;
}
voidCommandLineInterface::nextCommand() {
if(callbacks.empty()) {
return;
}
std::string command;
std::cout << "> ";
std::getline(std::cin, command);
while(callbacks.find(command) == callbacks.end()) {
std::cout << "Unknown command!" << std::endl;
std::cout << "> ";
std::getline(std::cin, command);
}
callbacks[command]();
}
voidCommandLineInterface::printHelp() {
for(constauto &[key, value] : callbacks) {
std::cout << key << std::endl;
}
}