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