-
-
Notifications
You must be signed in to change notification settings - Fork 245
/
OptionDocumentationGenerator.cpp
75 lines (58 loc) · 2.15 KB
/
OptionDocumentationGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/******************************************************************************
*
* C++ Insights, copyright (C) by Andreas Fertig
* Distributed under an MIT license. See LICENSE for details
*
****************************************************************************/
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
/// \brief Create a markdown file which contains the information about the option.
static bool CreateFile(const std::string& optionName, bool optionDefault, const char* description)
{
const std::string mdFileName{"opt-" + optionName + ".md"};
ofstream mdFile{mdFileName};
if(not mdFile.is_open()) {
return false;
}
cout << "Generating: " << mdFileName << "\n";
std::string linkName{optionName};
std::replace(linkName.begin(), linkName.end(), '-', '_');
mdFile << "# " << optionName << " {#" << linkName << "}\n";
mdFile << description << "\n\n";
mdFile << "__Default:__ " << (optionDefault ? "On" : "Off") << "\n\n";
mdFile << "__Examples:__\n\n";
mdFile << "```.cpp\n";
mdFile << optionName << "-source\n";
mdFile << "```\n\n";
mdFile << "transforms into this:\n\n";
mdFile << "```.cpp\n";
mdFile << optionName << "-transformed\n";
mdFile << "```\n";
mdFile.close();
return true;
}
int main()
{
#define INSIGHTS_OPT(opt, name, deflt, description, category) CreateFile(opt, deflt, description);
#include "../InsightsOptions.def"
#undef INSIGHTS_OPT
ofstream mdFile{"CommandLineOptions.md"};
if(not mdFile.is_open()) {
return -1;
}
mdFile << "# C++ Insights command line options {#command_line_options}\n\n";
std::vector<std::string> options{};
#define INSIGHTS_OPT(opt, name, deflt, description, category) options.emplace_back(opt);
#include "../InsightsOptions.def"
sort(options.begin(), options.end());
for(const auto& opt : options) {
std::string linkName{opt};
std::replace(linkName.begin(), linkName.end(), '-', '_');
//* [alt-syntax-for](@ref alt_syntax_for)
mdFile << "* [" << opt << "](@ref " << linkName << ")\n";
}
}