lordgamez commented on a change in pull request #1220:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1220#discussion_r765684215
##########
File path: libminifi/include/core/yaml/CheckRequiredField.h
##########
@@ -49,7 +53,23 @@ namespace yaml {
* not present in 'yamlNode'
*/
void checkRequiredField(
- const YAML::Node *yamlNode, const std::string &fieldName, const
std::shared_ptr<logging::Logger>& logger, const std::string &yamlSection = "",
const std::string &errorMessage = "");
+ const YAML::Node *yamlNode, const std::string &fieldName, const
std::shared_ptr<logging::Logger>& logger, const std::string &yamlSection = "",
std::string errorMessage = "");
+
+template<typename T>
+T parseRequiredField(const YAML::Node* yamlNode,
+ const std::vector<std::string>& alternateNames, const
std::shared_ptr<logging::Logger>& logger,
+ const std::string &yamlSection, std::function<T(const YAML::Node&)>
parser, std::string errorMessage = "") {
+ for (const auto& name : alternateNames) {
+ if (yaml::isFieldPresent(yamlNode, name)) {
+ return parser((*yamlNode)[name]);
+ }
+ }
+ if (errorMessage.empty()) {
+ errorMessage = buildErrorMessage(yamlNode, alternateNames, yamlSection);
+ }
+ logger->log_error(errorMessage.c_str());
+ throw std::invalid_argument(errorMessage);
+}
Review comment:
Thanks for your comments, I appreciate the effort you put into them. I
updated most of the points listed, unfortunately I could not avoid allocating
the vector used for the alternate name so I didn't use `gsl::span` and also out
implementation of `StringUtils::join` does not work with `std::string_view`s so
I had to fallback to strings.
--
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]