Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Pavel Zhukov
Kea
Commits
c671e542
Commit
c671e542
authored
Jun 12, 2018
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[5422] Template handling improved.
parent
e833c576
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
25 deletions
+35
-25
tools/cmd-docgen/cmd_docgen.cc
tools/cmd-docgen/cmd_docgen.cc
+35
-25
No files found.
tools/cmd-docgen/cmd_docgen.cc
View file @
c671e542
...
...
@@ -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
,
"<"
,
"<"
);
...
...
@@ -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:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment