szaszm commented on code in PR #1665:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1665#discussion_r1334324696


##########
libminifi/include/core/PropertyDefinition.h:
##########
@@ -39,7 +39,7 @@ struct PropertyDefinition {
   std::array<std::string_view, NumDependentProperties> dependent_properties;
   std::array<std::pair<std::string_view, std::string_view>, 
NumExclusiveOfProperties> exclusive_of_properties;
   std::optional<std::string_view> default_value;
-  gsl::not_null<const PropertyType*> type = 
gsl::make_not_null(&StandardPropertyTypes::VALID_TYPE);
+  gsl::not_null<const PropertyType*> type = gsl::make_not_null<const 
PropertyType*>(&StandardPropertyTypes::VALID_TYPE);

Review Comment:
   Why are explicit template arguments needed? Wouldn't this work with template 
argument deduction, and maybe conversion to `const` if necessary?



##########
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"
+    "-->";

Review Comment:
   A raw string literal would be better for this purpose.
   ```suggestion
   inline constexpr std::string_view APACHE_LICENSE = R"license(<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
       http://www.apache.org/licenses/LICENSE-2.0
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   -->)license";
   ```



##########
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:
   I'd apply this function to its own name. :)
   Just to be consistent with the naming of other functions. I also wonder why 
is it a function object: a simple function can also be `constexpr`, and be 
passed by its address to `sort`.
   ```suggestion
   constexpr auto lowercaseFirst = [](const auto& key_value) {
     return minifi::utils::StringUtils::toLower(key_value.first);
   };
   ```



-- 
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]

Reply via email to