22#include "common/sys/rc.h"
23#include "common/lang/string.h"
24#include "common/lang/string_view.h"
25#include "oblsm/client/cliutil/defs.h"
28#include "readline/history.h"
29#include "readline/readline.h"
32#define MAX_MEM_BUFFER_SIZE 8192
36inline const string HISTORY_FILE = string(getenv(
"HOME")) +
"/.oblsm_cli.history";
37inline time_t last_history_write_time = 0;
39inline std::string my_readline(
const string &prompt)
41 int size = history_length;
43 read_history(HISTORY_FILE.c_str());
45 std::ofstream historyFile(HISTORY_FILE, std::ios::app);
46 if (historyFile.is_open()) {
51 char *line = readline(prompt.c_str());
53 if (line !=
nullptr && line[0] != 0) {
57 if (std::time(
nullptr) - last_history_write_time > 5) {
58 write_history(HISTORY_FILE.c_str());
65inline std::string my_readline(
const std::string &prompt)
69 if (std::getline(std::cin, buffer)) {
94#define MAP_COMMAND(cmd) token_map_[string{ObLsmCliUtil::strcmd(ObLsmCliCmdType::cmd)}] = ObLsmCliCmdType::cmd
106 void init(string_view command)
115 bool out_of_range() {
return p_ >= command_.size(); }
116 void skip_blank_space();
117 RC parse_string(
string &res);
119 std::map<string, ObLsmCliCmdType> token_map_;
121 string_view command_;
135 bool bounds[2] = {
false,
false};
138 RC parse(string_view command);