Skip to content
Snippets Groups Projects
Commit 851cc344 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

section extraction from help fixed

parent 9eb4e577
No related branches found
No related tags found
1 merge request!289M300433/python interaface integration 1
......@@ -58,34 +58,50 @@ ModListOptions::parse_request(const std::string &requestString)
return true;
}
std::pair<std::map<std::string, std::vector<std::string>>, std::map<std::string, std::vector<std::string>>>
std::pair<std::map<std::string, std::vector<std::string>>, std::map<std::string, std::pair<std::string, std::vector<std::string>>>>
create_help_sections(const CdoHelp &p_help)
{
std::map<std::string, std::vector<std::string>> sections = {};
std::map<std::string, std::vector<std::string>> operators = {};
std::map<std::string, std::string> oper_synopsis = {};
std::string key;
std::string operator_name;
bool operator_section_active = true;
bool synopsis_active = true;
for (auto &line : p_help)
{
std::cout << line << std::endl;
bool is_all_caps = std::all_of(begin(line), end(line), [](char c) { return isupper(c); });
if (line.compare("OPERATORS") == 0)
{
operator_section_active = true;
synopsis_active = false;
}
else if (line.compare("SYNOPSIS") == 0)
{
key = line;
operator_section_active = false;
synopsis_active = true;
}
else if (is_all_caps == true)
{
key = line;
sections[key] = std::vector<std::string>();
operator_section_active = false;
synopsis_active = false;
}
else if (operator_section_active == true)
{
if (line.find_first_not_of(' ') == 4)
int op_name_padding = 4;
if (line.find_first_not_of(' ') == op_name_padding)
{
operator_name = line.substr(4, line.find(' ', 4));
int first_space_after_name = line.find_first_of(' ', op_name_padding);
int name_length = first_space_after_name - op_name_padding;
operator_name = line.substr(op_name_padding,name_length);
operators[operator_name] = std::vector<std::string>{ std::string(line) };
}
else
......@@ -93,13 +109,60 @@ create_help_sections(const CdoHelp &p_help)
operators[operator_name].push_back(std::string(line));
}
}
else if (synopsis_active == true)
{
//std::cout << "we found a synopsis" << std::endl;
int op_name_padding = 4;
std::size_t general_op_desc_pos = line.find("<operator>");
if(general_op_desc_pos != std::string::npos){
//std::cout << "we found a <operator>" << std::endl;
constexpr std::size_t len_generic = std::string("<operator>").size();
auto cleaned_line = std::string(line).erase(0,general_op_desc_pos + len_generic);
std::cout << cleaned_line << " " << general_op_desc_pos << std::endl;
sections["SYNOPSIS"] = {cleaned_line};
}
else if (line.find_first_not_of(' ') == op_name_padding)
{
int first_space_after_name = line.find_first_of("[, ", op_name_padding);
int name_length = first_space_after_name - op_name_padding;
operator_name = line.substr(op_name_padding,name_length);
oper_synopsis[operator_name] = std::string(line);
std::cout << "we added "<< line << " to " <<operator_name << std::endl;
}
}
else
{
sections[key].push_back(std::string(line));
}
}
return std::make_pair(sections, operators);
std::cout<< "we got here " << __LINE__ << " " << __FILE__ << std::endl;
std::map<std::string, std::pair<std::string, std::vector<std::string>>> oper_syn_map;
for(const auto &op : operators){
std::string syn = "";
auto it = oper_synopsis.find(op.first);
if(it != oper_synopsis.end()){
syn = oper_synopsis[op.first];
std::cout << "LOOK HERE " << syn << std::endl;
oper_synopsis.erase(it);
}
else
{
std::cout << op.first << std::endl;
std::cout << (sections.find("SYNOPSIS") != sections.end()) << std::endl;
syn = " " + op.first + " " + sections["SYNOPSIS"][0];
}
std::cout << syn << std::endl;
oper_syn_map[op.first] = std::make_pair(syn,op.second);
}
for(auto &syn : oper_synopsis){
std::cout << "added " << syn.first << " to map, with value = " << syn.second << std::endl;
oper_syn_map[syn.first].first = syn.second;
}
return std::make_pair(sections, oper_syn_map);
}
std::string
......
......@@ -27,7 +27,7 @@ struct ModListOptions
std::string get_operator_description(const std::string &p_current_op_name, const std::vector<std::string> &p_help);
void operator_print_list(ModListOptions &p_modListOpt);
std::pair<std::map<std::string, std::vector<std::string>>, std::map<std::string, std::vector<std::string>>>
std::pair<std::map<std::string, std::vector<std::string>>, std::map<std::string, std::pair<std::string, std::vector<std::string>>>>
create_help_sections(const CdoHelp &p_help);
void cdo_print_help(const char **help);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment