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++;
}
"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 "
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);
f << endl;
f << "<!-- autogenerated using cmd_docgen. Do not edit by hand! -->" << endl;
}
-
+
void generateOutput() {
-
+
stringstream f;
generateCopyright(f);
-
+
f << "<chapter xmlns=\"http://docbook.org/ns/docbook\" version=\"5.0\" xml:id=\"api\">"
<< endl;
f << " <title>Management API Reference</title>" << endl;
-
+
// Generate initial list of commands
f << " <para>Kea currently supports " << cmds_.size() << " commands:" << endl
<< " <orderedlist>" << endl;
-
+
for (auto cmd : cmds_) {
f << " <listitem><simpara>" << cmd.first << "</simpara></listitem>" << endl;
}
-
+
f << " </orderedlist>" << endl;
f << " </para>" << endl;
-
+
// Generate actual commands references.
generateCommands(f);
-
+
f << "</chapter>" << 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 << "<!-- start of " << cmd.first << " -->" << endl;
f << "<section xml:id=\"reference-" << cmd.first << "\">" << endl;
start_pos += to.length();
}
}
-
+
string escapeString(string txt) {
replaceAll(txt, "<", "<");
<< endl << endl;
// description and examples
- f << "<para>Description and examples: See <xref linkend=\"cmd-"
+ f << "<para>Description and examples: See <xref linkend=\"cmd-"
<< cmd->get("name")->stringValue() << "\"/></para>" << endl << endl;
// Command syntax: