14const std::string ConfigurationHelpPrinter::allStr =
"all";
15const std::string ConfigurationHelpPrinter::availStr =
"avail";
17static std::string h1 =
"";
18static std::string h1End =
"";
19static std::string h2 =
"";
20static std::string h2End =
"";
21static std::string b =
"";
22static std::string u =
"";
23static std::string i =
"";
24static std::string bEnd =
"";
25static std::string uEnd =
"";
26static std::string iEnd =
"";
28static std::string section(
const std::string& title) {
return h1 + title + h1End; }
30static std::string option(
const std::string& name) {
return h2 + name + h2End; }
32static std::string defaultVal(
const std::string& name) {
return b + name + bEnd; }
34static std::string type(
const std::string& desc) {
return i + desc + iEnd; }
36std::ostream& ConfigurationHelpPrinter::print(
37 std::ostream& os,
const ConfigurationHelp::HelpMap& map,
const std::string& target)
39 if (target == allStr) {
41 for (
auto configEntry : map) {
42 os << section(configEntry.first) << std::endl << std::endl;
43 for (
auto optionEntry : configEntry.second) {
44 os << optionEntry << std::endl;
48 }
else if (target == availStr || target.empty()) {
50 for (
auto configEntry : map) {
51 os << section(configEntry.first) << std::endl;
52 for (
auto optionEntry : configEntry.second) {
53 os << optionEntry.name << std::endl;
59 std::regex targex(target);
61 for (
auto configEntry : map) {
63 if (std::regex_search(configEntry.first, sm, targex)) {
65 os << section(configEntry.first) << std::endl << std::endl;
66 for (
auto optionEntry : configEntry.second) {
67 os << optionEntry << std::endl;
73 unsigned optionCount = 0;
74 for (
auto optionEntry : configEntry.second) {
75 if (std::regex_search(optionEntry.name, sm, targex))
80 os << section(configEntry.first) << std::endl << std::endl;
82 for (
auto optionEntry : configEntry.second) {
83 if (std::regex_search(optionEntry.name, sm, targex)) {
84 os << optionEntry << std::endl;
92 os <<
"No configuration options matching \"" << target <<
"\" were found." << std::endl;
98std::ostream& ConfigurationHelpPrinter::print(std::ostream& os,
const ConfigurationHelp& help)
101 case (ConfigType::STRING):
102 return printString(os, help);
104 case (ConfigType::NUMERIC):
105 return printNumeric(os, help);
107 case (ConfigType::INTEGER):
108 return printInteger(os, help);
110 case (ConfigType::MODULE):
111 return printModule(os, help);
113 case (ConfigType::BOOLEAN):
114 return printBoolean(os, help);
121std::ostream& ConfigurationHelpPrinter::printString(std::ostream& os,
const ConfigurationHelp& help)
123 os << option(help.name) << std::endl;
124 os << type(
"string");
125 if (!help.defaultValue.empty()) {
126 os <<
" (default = " << help.defaultValue <<
")";
129 os << help.text << std::endl;
133std::ostream& ConfigurationHelpPrinter::printNumeric(
134 std::ostream& os,
const ConfigurationHelp& help)
136 os << option(help.name) << std::endl;
137 os << type(
"numeric") +
" range: " << help.range[0] <<
"—" << help.range[1] <<
" "
139 if (!help.defaultValue.empty()) {
140 os <<
" (default = " << help.defaultValue <<
")";
143 os << help.text << std::endl;
147std::ostream& ConfigurationHelpPrinter::printInteger(
148 std::ostream& os,
const ConfigurationHelp& help)
150 os << option(help.name) << std::endl;
151 os << type(
"integer") +
" range: " << help.range[0] <<
"—" << help.range[1] <<
" "
153 if (!help.defaultValue.empty()) {
154 os <<
" (default = " << help.defaultValue <<
")";
157 os << help.text << std::endl;
161std::ostream& ConfigurationHelpPrinter::printModule(std::ostream& os,
const ConfigurationHelp& help)
163 os << option(help.name) << std::endl;
164 os << type(
"module") +
" [";
166 os << defaultVal(help.defaultValue);
167 for (
auto impl : help.range) {
168 if (impl != help.defaultValue) {
172 os <<
"]" << std::endl;
173 os << help.text << std::endl;
176std::ostream& ConfigurationHelpPrinter::printBoolean(
177 std::ostream& os,
const ConfigurationHelp& help)
179 os << option(help.name) << std::endl;
180 os << type(
"Boolean") +
" ";
181 if (!help.defaultValue.empty()) {
182 os <<
" (default = " << help.defaultValue <<
")";
185 os << help.text << std::endl;
189static std::string ansiMode(std::string mode) {
return "\033[" + mode +
"m"; }
191void ConfigurationHelpPrinter::setOutput(Output out)
193 if (out == Output::ANSI) {
194 std::string esc =
"\033[";
195 std::string cls =
"m";
201 bEnd = uEnd = iEnd = h1End = h2End = ansiMode(
"");
202 }
else if (out == Output::MARKDOWN) {