szaszm commented on code in PR #1665:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1665#discussion_r1335913943
##########
minifi_main/AgentDocs.cpp:
##########
@@ -64,130 +65,145 @@ std::string formatAllowedValues(const
minifi::core::Property& property) {
std::string formatDescription(std::string_view description_view, bool
supports_expression_language = false) {
std::string description{description_view};
- org::apache::nifi::minifi::utils::StringUtils::replaceAll(description, "\n",
"<br/>");
+ minifi::utils::StringUtils::replaceAll(description, "\n", "<br/>");
return supports_expression_language ? description + "<br/>**Supports
Expression Language: true**" : description;
}
std::string formatListOfRelationships(std::span<const
minifi::core::RelationshipDefinition> relationships) {
return minifi::utils::StringUtils::join(", ", relationships, [](const auto&
relationship) { return relationship.name; });
}
-} // namespace
+inline constexpr std::string_view APACHE_LICENSE = "<!--\n"
+ "Licensed to the Apache Software Foundation (ASF) under one or more\n"
+ "contributor license agreements. See the NOTICE file distributed with\n"
+ "this work for additional information regarding copyright ownership.\n"
+ "The ASF licenses this file to You under the Apache License, Version 2.0\n"
+ "(the \"License\"); you may not use this file except in compliance with\n"
+ "the License. You may obtain a copy of the License at\n"
+ " http://www.apache.org/licenses/LICENSE-2.0\n"
+ "Unless required by applicable law or agreed to in writing, software\n"
+ "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.\n"
+ "See the License for the specific language governing permissions and\n"
+ "limitations under the License.\n"
+ "-->";
+
+void writeHeader(std::ostream& docs, const std::vector<std::pair<std::string,
minifi::ClassDescription>>& class_descriptions) {
+ docs << APACHE_LICENSE;
+
+ docs << "\n\n## Table of Contents\n\n";
+ for (const auto& [name, documentation] : class_descriptions) {
+ docs << "- [" << name << "](#" << name << ")\n";
+ }
+}
-namespace org::apache::nifi::minifi::docs {
+void writeName(std::ostream& docs, std::string_view name) {
+ docs << "\n\n## " << name;
+}
+
+void writeDescription(std::ostream& docs, const minifi::ClassDescription&
documentation) {
+ docs << "\n\n### Description\n\n";
+ docs << documentation.description_;
+}
-std::string AgentDocs::extractClassName(const std::string &processor) {
- auto positionOfLastDot = processor.find_last_of('.');
- if (positionOfLastDot != std::string::npos) {
- return processor.substr(positionOfLastDot + 1);
+void writeProperties(std::ostream& docs, const minifi::ClassDescription&
documentation) {
+ docs << "\n\n### Properties";
+ docs << "\n\nIn the list below, the names of required properties appear in
bold. Any other properties (not in bold) are considered optional. "
+ << "The table also indicates any default values, and whether a property
supports the NiFi Expression Language.";
+ minifi::docs::Table properties{{"Name", "Default Value", "Allowable Values",
"Description"}};
+ for (const auto &property : documentation.class_properties_) {
+ properties.addRow({
+ formatName(property.getName(), property.getRequired()),
+ property.getDefaultValue().to_string(),
+ formatAllowedValues(property),
+ formatDescription(property.getDescription(),
property.supportsExpressionLanguage())
+ });
}
- return processor;
+ docs << "\n\n" << properties.toString();
}
-void AgentDocs::generate(const std::filesystem::path& docsdir, std::ostream
&genStream) {
- std::map<std::string, ClassDescription> processorSet;
- for (const auto &group : minifi::AgentBuild::getExtensions()) {
- struct Components descriptions =
build_description_.getClassDescriptions(group);
- for (const auto& processor_description : descriptions.processors_) {
-
processorSet.insert(std::make_pair(extractClassName(processor_description.full_name_),
processor_description));
- }
+void writeDynamicProperties(std::ostream& docs, const
minifi::ClassDescription& documentation) {
+ if (documentation.dynamic_properties_.empty()) { return; }
+
+ docs << "\n### Dynamic Properties\n\n";
+ minifi::docs::Table dynamic_properties{{"Name", "Value", "Description"}};
+ for (const auto &dynamic_property : documentation.dynamic_properties_) {
+ dynamic_properties.addRow({
+ formatName(dynamic_property.name, false),
+ std::string(dynamic_property.value),
+ formatDescription(dynamic_property.description,
dynamic_property.supports_expression_language)
+ });
}
- for (const auto &processor : processorSet) {
- const auto& filename = docsdir / processor.first;
- std::ofstream outfile(filename);
-
- outfile << "## " << processor.first << "\n\n";
- outfile << "### Description\n\n";
- outfile << processor.second.description_ << '\n';
-
- outfile << "\n### Properties\n\n";
- outfile << "In the list below, the names of required properties appear in
bold. Any other properties (not in bold) are considered optional. "
- << "The table also indicates any default values, and whether a
property supports the NiFi Expression Language.\n\n";
-
- Table properties{{"Name", "Default Value", "Allowable Values",
"Description"}};
- for (const auto &prop : processor.second.class_properties_) {
- properties.addRow({
- formatName(prop.getName(), prop.getRequired()),
- prop.getDefaultValue().to_string(),
- formatAllowedValues(prop),
- formatDescription(prop.getDescription(),
prop.supportsExpressionLanguage())});
- }
- outfile << properties.toString() << '\n';
-
- if (!processor.second.dynamic_properties_.empty()) {
- outfile << "### Dynamic Properties\n\n";
- Table dynamic_properties{{"Name", "Value", "Description"}};
- for (const auto& dynamic_property :
processor.second.dynamic_properties_) {
- dynamic_properties.addRow({
- formatName(dynamic_property.name, false),
- std::string(dynamic_property.value),
- formatDescription(dynamic_property.description,
dynamic_property.supports_expression_language)
- });
- }
- outfile << dynamic_properties.toString() << '\n';
- }
+ docs << dynamic_properties.toString();
+}
- outfile << "### Relationships\n\n";
- Table relationships{{"Name", "Description"}};
- for (const auto &rel : processor.second.class_relationships_) {
- relationships.addRow({rel.getName(),
formatDescription(rel.getDescription())});
- }
- outfile << relationships.toString() << '\n';
-
- if (!processor.second.output_attributes_.empty()) {
- outfile << "### Output Attributes\n\n";
- Table output_attributes{{"Attribute", "Relationship", "Description"}};
- for (const auto& output_attribute : processor.second.output_attributes_)
{
- output_attributes.addRow({
- std::string(output_attribute.name),
- formatListOfRelationships(output_attribute.relationships),
- formatDescription(output_attribute.description)});
- }
- outfile << output_attributes.toString() << '\n';
- }
+void writeRelationships(std::ostream& docs, const minifi::ClassDescription&
documentation) {
+ docs << "\n### Relationships\n\n";
+ minifi::docs::Table relationships{{"Name", "Description"}};
+ for (const auto &rel : documentation.class_relationships_) {
+ relationships.addRow({rel.getName(),
formatDescription(rel.getDescription())});
}
+ docs << relationships.toString();
+}
+
+void writeOutputAttributes(std::ostream& docs, const minifi::ClassDescription&
documentation) {
+ if (documentation.output_attributes_.empty()) { return; }
+
+ docs << "\n### Output Attributes";
+ minifi::docs::Table output_attributes{{"Attribute", "Relationship",
"Description"}};
+ for (const auto &output_attribute : documentation.output_attributes_) {
+ output_attributes.addRow({
+ std::string(output_attribute.name),
+ formatListOfRelationships(output_attribute.relationships),
+ formatDescription(output_attribute.description)});
+ }
+ docs << "\n\n" << output_attributes.toString();
+}
- std::map<std::string, std::filesystem::path> fileList;
- auto fileFind = [&fileList](const std::filesystem::path& base_path, const
std::filesystem::path& file) -> bool {
- if (file.string().find(".extra") == std::string::npos) {
- auto file_name = file.string();
- ranges::actions::transform(file_name, [](auto ch) { return
::tolower(static_cast<unsigned char>(ch)); });
- fileList.emplace(file_name, base_path / file);
+std::string extractClassName(const std::string& full_class_name) {
+ return minifi::utils::StringUtils::split(full_class_name, ".").back();
+}
+
+constexpr auto LowercaseFirst = [](const auto& key_value) {
+ return minifi::utils::StringUtils::toLower(key_value.first);
+};
Review Comment:
Yeah, you're right, taking the address of a generic function doesn't really
work. `std::less` works, because it's a function object, and the template
argument deduction is done at the call operator. But with function pointers,
you can't have a pointer to a function that hasn't been instantiated yet, it
has to be a template specialization. My compiler explorer link:
https://godbolt.org/z/bsP8KjG7T
I would've written the same as your initial version, except for the
identifier casing. I'm OK with either version, we can leave it as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]