]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5422] Template handling improved.
authorTomek Mrugalski <tomasz@isc.org>
Tue, 12 Jun 2018 21:52:57 +0000 (23:52 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 29 Oct 2019 17:57:12 +0000 (18:57 +0100)
tools/cmd-docgen/cmd_docgen.cc

index aaa5c1a5827b5d90688af07755fd4764a83acc1a..93641cc794da6ab0de5616d2b6662026b90ee1c9 100644 (file)
@@ -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 << "<!-- 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;
@@ -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, "<", "&lt;");
@@ -194,7 +204,7 @@ void generateCommand(stringstream& f, const ElementPtr& cmd) {
       << 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: