diff options
author | Tomek Mrugalski <tomasz@isc.org> | 2018-10-02 13:16:24 +0200 |
---|---|---|
committer | Tomek Mrugalski <tomasz@isc.org> | 2019-10-29 18:57:13 +0100 |
commit | c6b9d78908fc9d61cfb62bfa48be71cc33a7a75e (patch) | |
tree | 5571eced697cbd64f99f8e44df59e366bf4fb163 /tools | |
parent | [#10,!3] API reference is now an appendix (diff) | |
download | kea-c6b9d78908fc9d61cfb62bfa48be71cc33a7a75e.tar.xz kea-c6b9d78908fc9d61cfb62bfa48be71cc33a7a75e.zip |
[#10,!3] docgen moved to doc/docgen
Diffstat (limited to 'tools')
-rw-r--r-- | tools/cmd-docgen/.gitignore | 2 | ||||
-rw-r--r-- | tools/cmd-docgen/Makefile.am | 20 | ||||
-rw-r--r-- | tools/cmd-docgen/cmds-list | 65 | ||||
-rwxr-xr-x | tools/cmd-docgen/generate-templates | 18 | ||||
-rw-r--r-- | tools/cmd-docgen/kea_docgen.cc | 397 |
5 files changed, 0 insertions, 502 deletions
diff --git a/tools/cmd-docgen/.gitignore b/tools/cmd-docgen/.gitignore deleted file mode 100644 index 568bae86bf..0000000000 --- a/tools/cmd-docgen/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -cmd-docgen -*.json diff --git a/tools/cmd-docgen/Makefile.am b/tools/cmd-docgen/Makefile.am deleted file mode 100644 index 72d8bd94c6..0000000000 --- a/tools/cmd-docgen/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -SUBDIRS = . - -AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib -AM_CPPFLAGS += $(BOOST_INCLUDES) - -AM_CXXFLAGS = $(KEA_CXXFLAGS) - -AM_LDFLAGS = -static - -if GENERATE_DOCS -noinst_PROGRAMS = kea-docgen -kea_docgen_SOURCES = kea_docgen.cc - -# For bare distcheck -EXTRA_DIST = cmd_docgen - -kea_docgen_LDADD = $(top_builddir)/src/lib/cc/libkea-cc.la -kea_docgen_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la - -endif diff --git a/tools/cmd-docgen/cmds-list b/tools/cmd-docgen/cmds-list deleted file mode 100644 index 6a6bb62a9a..0000000000 --- a/tools/cmd-docgen/cmds-list +++ /dev/null @@ -1,65 +0,0 @@ -build-report -cache-clear -cache-get -cache-insert -cache-load -cache-remove -cache-write -config-get -config-reload -config-set -config-test -config-write -dhcp-disable -dhcp-enable -ha-heartbeat -ha-scopes -ha-sync -lease4-add -lease4-del -lease4-get -lease4-get-all -lease4-update -lease4-wipe -lease6-add -lease6-del -lease6-get -lease6-get-all -lease6-update -lease6-wipe -leases-reclaim -libreload -list-commands -network4-add -network4-del -network4-get -network4-list -network4-subnet-add -network4-subnet-del -network6-add -network6-del -network6-get -network6-list -network6-subnet-add -network6-subnet-del -reservation-add -reservation-del -reservation-get -shutdown -stat-lease4-get -stat-lease6-get -statistic-get -statistic-get-all -statistic-remove -statistic-remove-all -statistic-reset -statistic-reset-all -subnet4-add -subnet4-del -subnet4-get -subnet4-list -subnet6-add -subnet6-del -subnet6-get -subnet6-list -version-get diff --git a/tools/cmd-docgen/generate-templates b/tools/cmd-docgen/generate-templates deleted file mode 100755 index 7f5353f379..0000000000 --- a/tools/cmd-docgen/generate-templates +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -while read -r LINE; do - F=$LINE.json - echo "{" > $F - echo " \"name\": \"$LINE\",\n" >> $F - echo " \"brief\": \"a sentence or two explaining what this command does\",\n" >> $F - echo " \"support\": [ \"kea-dhcp4\", \"kea-dhcp6\" ],\n" >> $F - echo " \"avail\": \"first version, possible a hook library name and (premium) if applicable\",\n" >> $F - - echo " \"cmd-syntax\": \"Syntax of the command\",\n" >> $F - echo " \"cmd-comment\": \"Possibly some extra comments after the syntax.\",\n" >> $F - - echo " \"resp-syntax\": \"Syntax of the response\",\n" >> $F - echo " \"resp-comment\": \"Optional extra comments after the respone syntax.\"\n" >> $F - echo "}" >> $F - - echo "$LINE generated." -done < cmds-list diff --git a/tools/cmd-docgen/kea_docgen.cc b/tools/cmd-docgen/kea_docgen.cc deleted file mode 100644 index 41da9f9bab..0000000000 --- a/tools/cmd-docgen/kea_docgen.cc +++ /dev/null @@ -1,397 +0,0 @@ -#include <iostream> -#include <fstream> -#include <sstream> -#include <vector> -#include <map> -#include <set> - -#include <exceptions/exceptions.h> -#include <cc/data.h> - -using namespace std; -using namespace isc; -using namespace isc::data; - - - -class DocGen { -public: - - const string OUTPUT = "guide/api.xml"; - - bool verbose = false; - - void loadFiles(const vector<string>& files) { - - map <string, ElementPtr> commands; - - int cnt = 0; - - try { - for (auto f : files) { - 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 << "loaded, sanity check..."; - - sanityCheck(f, x); - - cmds_.insert(make_pair(cmd, x)); - cout << " looks ok." << endl; - - cnt++; - } - } catch (const Unexpected& e) { - isc_throw(Unexpected, e.what() << " while processing " - << cnt + 1 << " file out of " << files.size()); - } - - cout << "Loaded " << cmds_.size() << " commands out of " << files.size() - << " file(s)" << endl; - } - - - void requireString(const ElementPtr& x, const string& name, const string& fname) { - if (!x->contains(name)) { - isc_throw(Unexpected, "Mandatory '" + name + " field missing while " - "processing file " + fname); - } - if (x->get(name)->getType() != Element::string) { - isc_throw(BadValue, "'" + name + " field is present, but is not a string" - " in file " + fname); - } - if (x->get(name)->stringValue().empty()) { - isc_throw(BadValue, "'" + name + " field is present, is a string, but is " - "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 " - "processing file " + fname); - } - if (x->get(name)->getType() != Element::list) { - 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); - requireList (x, "support", fname); - requireString(x, "avail", fname); - requireString(x, "brief", fname); - - // They're optional. - //requireString(x, "cmd-syntax", fname); - //requireString(x, "cmd-comment", fname); - //requireString(x, "resp-syntax", fname); - //requireString(x, "resp-comment", fname); - } - - void generateCopyright(stringstream& f) { - f << "<!--" << endl; - f << " - Copyright (C) 2018 Internet Systems Consortium, Inc. (\"ISC\")" << endl; - f << " -" << endl; - f << " - This Source Code Form is subject to the terms of the Mozilla Public" << endl; - f << " - License, v. 2.0. If a copy of the MPL was not distributed with this" << endl; - f << " - file, You can obtain one at http://mozilla.org/MPL/2.0/." << endl; - f << " -->" << endl; - f << endl; - f << "<!-- autogenerated using cmd_docgen. Do not edit by hand! -->" << endl; - } - - void generateCmdLink(stringstream& f, const string& cmd) { - f << "<command><link linkend=\"ref-" << cmd << "\">" << cmd << "</link></command>" << endl; - } - - void generateLists(stringstream& f) { - // Generate a list of all commands - f << " <para>Kea currently supports " << cmds_.size() << " commands:" << endl; - - bool first = true; - for (auto cmd : cmds_) { - if (!first) { - f << ", "; - generateCmdLink(f, cmd.first); - } - - first = false; - } - - f << ".</para>" << endl; - - // Generate a list of components: - set<string> all_daemons; - set<string> all_hooks; - for (auto cmd : cmds_) { - auto daemons = cmd.second->get("support"); - auto hook = cmd.second->get("hook"); - for (int i = 0; i < daemons->size(); i++) { - string daemon = daemons->get(i)->stringValue(); - if (all_daemons.find(daemon) == all_daemons.end()) { - all_daemons.insert(daemon); - } - } - if (hook) { - string hook_txt = hook->stringValue(); - if (all_hooks.find(hook_txt) == all_hooks.end()) { - all_hooks.insert(hook_txt); - } - } - } - - cout << "### " << all_daemons.size() << " daemon(s) detected." << endl; - cout << "### " << all_hooks.size() << " hook lib(s) detected." << endl; - - for (auto daemon : all_daemons) { - f << "<para xml:id=\"commands-" << daemon << "\">" - << "Commands supported by " << daemon << " daemon: "; - - bool first = true; - for (auto cmd : cmds_) { - - first = true; - auto daemons = cmd.second->get("support"); - for (auto d : daemons->listValue()) { - if (d->stringValue() == daemon) { - if (!first) { - f << ", "; - } - generateCmdLink(f, cmd.first); - first = false; - break; // get to next command - } - } - } - - f << ".</para>" << endl; - } - - for (auto hook : all_hooks) { - f << "<para xml:id=\"commands-" << hook << "-lib\">" - << "Commands supported by " << hook << " hook library: "; - - bool first = true; - for (auto cmd : cmds_) { - - first = true; - auto daemon_hook = cmd.second->get("hook"); - if (!daemon_hook || daemon_hook->stringValue() != hook) { - continue; - } - if (!first) { - f << ", "; - } - generateCmdLink(f, cmd.first); - first = false; - } - - f << ".</para>" << endl; - } - - } - - void generateOutput() { - - stringstream f; - - generateCopyright(f); - - f << "<chapter xmlns=\"http://docbook.org/ns/docbook\" version=\"5.0\" xml:id=\"api\">" - << endl; - f << " <title>API Reference</title>" << endl; - - - generateLists(f); - - // Generate actual commands references. - generateCommands(f); - - f << "</chapter>" << endl; - - ofstream file(OUTPUT.c_str(), ofstream::trunc); - file << f.str(); - if (verbose) { - cout << "----------------" << endl; - cout << f.str(); - cout << "----------------" << endl; - } - file.close(); - - cout << "Output written to " << OUTPUT << endl; - } - - void generateCommands(stringstream& f){ - - for (auto cmd : cmds_) { - f << "<!-- start of " << cmd.first << " -->" << endl; - f << "<section xml:id=\"reference-" << cmd.first << "\">" << endl; - f << "<title>" << cmd.first << " reference</title>" << endl; - generateCommand(f, cmd.second); - f << "</section>" << endl; - f << "<!-- end of " << cmd.first << " -->" << endl; - f << endl; - } - } - -void replaceAll(std::string& str, const std::string& from, const std::string& to) { - if(from.empty()) - return; - size_t start_pos = 0; - while((start_pos = str.find(from, start_pos)) != std::string::npos) { - str.replace(start_pos, from.length(), to); - start_pos += to.length(); - } -} - -string escapeString(string txt) { - - replaceAll(txt, "<", "<"); - replaceAll(txt, ">", ">"); - return (txt); -} - -string standardResponseSyntax() { - stringstream t; - - t << "{" << endl - << " \"result\": <integer>," << endl - << " \"text\": <string>" << endl - << "}" << endl; - return (t.str()); -} - -string standardResponseComment() { - stringstream t; - - t << "Result is an integer representation of the status. Currently supported" - << " statuses are:" << endl - << "<itemizedlist>" << endl - << " <listitem><para>0 - success</para></listitem>" << endl - << " <listitem><para>1 - error</para></listitem>" << endl - << " <listitem><para>2 - unsupported</para></listitem>" << endl - << " <listitem><para>3 - empty (command was completed successfully, but " - << "no data was affected or returned)</para>" - << "</listitem>" << endl - << "</itemizedlist>" << endl; - return (t.str()); -} - -void generateCommand(stringstream& f, const ElementPtr& cmd) { - - // command overview - f << "<para xml:id=\"ref-" << cmd->get("name")->stringValue() << "\"><command>" - << cmd->get("name")->stringValue() << "</command> - " - << cmd->get("brief")->stringValue() << "</para>" << endl << endl; - - // command can be issued to the following daemons - f << "<para>Supported by: "; - ConstElementPtr daemons = cmd->get("support"); - for (int i = 0; i < daemons->size(); i++) { - if (i) { - f << ", "; - } - - f << "<command><link linkend=\"commands-" << daemons->get(i)->stringValue() - << "\">" << daemons->get(i)->stringValue() << "</link></command>"; - } - f << "</para>" << endl << endl; - - // availability - f << "<para>Availability: " << cmd->get("avail")->stringValue(); - auto hook = cmd->get("hook"); - if (hook) { - f << " (<link linkend=\"commands-" << hook->stringValue() << "-lib\">" - << hook->stringValue() << "</link>)"; - } else { - f << " (built-in)"; - } - - f << "</para>" << endl << endl; - - // description and examples - f << "<para>Description and examples: See <xref linkend=\"command-" - << cmd->get("name")->stringValue() << "\"/></para>" << endl << endl; - - // Command syntax: - f << "<para>Command syntax:" << endl; - if (cmd->contains("cmd-syntax")) { - f << " <screen>" << escapeString(cmd->get("cmd-syntax")->stringValue()) - << "</screen>" << endl; - } else { - f << " <screen>{" << endl - << " \"command\": \"" << cmd->get("name")->stringValue() << "\"" << endl - << "}</screen>" << endl; - } - if (cmd->contains("cmd-comment")) { - f << cmd->get("cmd-comment")->stringValue(); - } - f << "</para>" << endl << endl; - - // Response syntax - f << "<para>Response syntax:" << endl - << " <screen>"; - - if (cmd->contains("resp-syntax")) { - f << escapeString(cmd->get("resp-syntax")->stringValue()); - } else { - f << escapeString(standardResponseSyntax()); - } - f << "</screen>" << endl; - - if (cmd->contains("resp-comment")) { - f << cmd->get("resp-comment")->stringValue(); - } else { - f << standardResponseComment(); - } - f << "</para>" << endl << endl; -} - - map<string, ElementPtr> cmds_; -}; - -int main(int argc, const char*argv[]) { - - vector<string> files; - - for (int i = 1; i < argc; i++) { - files.push_back(string(argv[i])); - } - - cout << "Loading " << files.size() << " files(s)." << endl; - - try { - DocGen doc_gen; - - doc_gen.loadFiles(files); - - doc_gen.generateOutput(); - } catch (const exception& e) { - cerr << "ERROR: " << e.what() << endl; - } - - return (0); -} |