代码拉取完成,页面将自动刷新
//
// Created by GPL on 2021/7/24.
//
#ifndef C___COMMANDLINE_H
#define C___COMMANDLINE_H
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
/**
* @brief: Commandline parsing
* command format `git {action} [option | args...]`
* commands need to be done:
* cmdline, add, rm, mv, commit, diff, hash, differ
*/
class Commandline {
public:
// argument classes
class Option{
public:
// long options, short options, aliased options
vector<string> options;
// kind of values
vector<string> values;
string help;
Option(vector<string> options, string help = ""):options(move(options)), help(help){};
Option(string option, string value, string help = "")
{
this->options.emplace_back(option);
this->values.emplace_back(value);
this->help = help;
}
Option(vector<string> options,string values, string help){
this->options = move(options);
this->values.emplace_back(values);
this->help = help;
};
};
class Argument{
public:
string action;
string description;
vector<Option> options;
Argument(string action, string description=""):action(action),description(description){};
};
void add_action(string action){
this->arguments.emplace_back(Argument(action));
};
void add_help(string action, string description) {
bool if_find = false;
for(vector<Argument>::iterator it = arguments.begin();it != arguments.end();it++)
{
if(it->action == action)
{
if_find = true;
it->description = description;
break;
}
}
if(not if_find)
{
cout << "[" << action << "]" << "is not registered, please call add_action first" << endl;
}
}
void add_option(string action, string short_opt, string long_opt, string opt_help="");
void parse(int argc, char* argv[]) ;
void printHelp(ostream &os = cout) const;
string get_action(void){
return action;
}
vector<string> get_option(void);
private:
vector<Argument> arguments;
string action;
// pair of option and arguments
vector<pair<string,string>> opt_args;
};
#endif //C___COMMANDLINE_H
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。