easyVim  1.0
a simple vim-like text editor
parser.hpp
Go to the documentation of this file.
1 
8 #ifndef UTILS_PARSER_HPP
9 #define UTILS_PARSER_HPP
10 
11 #include <string>
12 #include <vector>
13 #include <unordered_map>
14 
15 namespace ev {
16 
22 class Parser{
23 public:
24  Parser();
25  ~Parser(){}
26 
32  std::unordered_map<std::string, std::string> parse(int argc, char** argv);
33 
39  void addCommand(std::string command, std::string help = ""){
40  commands.push_back(command);
41  helps.push_back(help);
42  }
43 
48  std::string help(){
49  std::string result =
50  " _ ___ \n"
51  " ___ ____ ________ _| | / (_)___ ___ \n"
52  " / _ \\/ __ `/ ___/ / / / | / / / __ `__ \\\n"
53  "/ __/ /_/ (__ ) /_/ /| |/ / / / / / / /\n"
54  "\\___/\\__,_/____/\\__, / |___/_/_/ /_/ /_/ \n"
55  " /____/ \n"; // logo
56  for (size_t i = 0; i < commands.size(); i++){
57  if (commands[i].size() > 1){
58  result += "--" + commands[i] + "\t" + helps[i] + "\n";
59  } else {
60  result += "-" + commands[i] + "\t" + helps[i] + "\n";
61  }
62  }
63  return result;
64  }
65 
66 private:
67  std::vector<std::string> commands;
68  std::vector<std::string> helps;
69 };
70 
71 }
72 
73 
74 
75 #endif //UTILS_PARSER_HPP
easyVim 解析器类
Definition: parser.hpp:22
std::unordered_map< std::string, std::string > parse(int argc, char **argv)
解析指令
Definition: parser.cpp:21
void addCommand(std::string command, std::string help="")
添加指令
Definition: parser.hpp:39
std::string help()
获取指令列表
Definition: parser.hpp:48