From: Tomek Mrugalski Date: Tue, 12 Jun 2018 21:52:57 +0000 (+0200) Subject: [5422] Template handling improved. X-Git-Tag: 176-update-to-sysrepo-0-7-6-release_base~185 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c671e542b6bc0a8710ecef00a29867f1878178ba;p=thirdparty%2Fkea.git [5422] Template handling improved. --- diff --git a/tools/cmd-docgen/cmd_docgen.cc b/tools/cmd-docgen/cmd_docgen.cc index aaa5c1a582..93641cc794 100644 --- a/tools/cmd-docgen/cmd_docgen.cc +++ b/tools/cmd-docgen/cmd_docgen.cc @@ -26,16 +26,26 @@ public: try { for (auto f : files) { - string cmd = f.substr(0, f.find(".")); - - cout << "Loading description of command " << cmd; + string cmd = f; + size_t pos = f.find_last_of('/'); + if (pos != string::npos) { + cmd = f.substr(pos + 1, -1); + } + cmd = cmd.substr(0, cmd.find(".")); + + if (cmd == "_template") { + cout << "Skipping template file (_template.json)" << endl; + continue; + } + + cout << "Loading description of command " << cmd << "... "; ElementPtr x = Element::fromJSONFile(f, false); - cout << "."; + cout << "loaded, sanity check..."; sanityCheck(f, x); - cout << "."; + cmds_.insert(make_pair(cmd, x)); - cout << "loaded" << endl; + cout << " looks ok." << endl; cnt++; } @@ -63,7 +73,7 @@ public: "empty in file " + fname); } } - + void requireList(const ElementPtr& x, const string& name, const string& fname) { if (!x->contains(name)) { isc_throw(Unexpected, "Mandatory '" + name + " field missing while " @@ -73,17 +83,17 @@ public: isc_throw(BadValue, "'" + name + " field is present, but is not a list " "in file " + fname); } - + ConstElementPtr l = x->get(name); - + if (l->size() == 0) { isc_throw(BadValue, "'" + name + " field is a list, but is empty in file " + fname); } - + // todo: check that every element is a string } - + void sanityCheck(const string& fname, const ElementPtr& x) { requireString(x, "name", fname); requireString(x, "brief", fname); @@ -107,42 +117,42 @@ public: f << endl; f << "" << endl; } - + void generateOutput() { - + stringstream f; generateCopyright(f); - + f << "" << endl; f << " Management API Reference" << endl; - + // Generate initial list of commands f << " Kea currently supports " << cmds_.size() << " commands:" << endl << " " << endl; - + for (auto cmd : cmds_) { f << " " << cmd.first << "" << endl; } - + f << " " << endl; f << " " << endl; - + // Generate actual commands references. generateCommands(f); - + f << "" << endl; - + cout << "----------------" << endl; ofstream file(OUTPUT.c_str(), ofstream::trunc); file << f.str(); - cout << f.str(); + // cout << f.str(); cout << "----------------" << endl; } - + void generateCommands(stringstream& f){ - + for (auto cmd : cmds_) { f << "" << endl; f << "
" << endl; @@ -163,7 +173,7 @@ void replaceAll(std::string& str, const std::string& from, const std::string& to start_pos += to.length(); } } - + string escapeString(string txt) { replaceAll(txt, "<", "<"); @@ -194,7 +204,7 @@ void generateCommand(stringstream& f, const ElementPtr& cmd) { << endl << endl; // description and examples - f << "Description and examples: See Description and examples: See get("name")->stringValue() << "\"/>" << endl << endl; // Command syntax: