lordgamez commented on code in PR #1638:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1638#discussion_r1311274597
##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -134,7 +135,93 @@ void writeJsonSchema(const
std::shared_ptr<minifi::Configure> &configuration, st
out << minifi::docs::generateJsonSchema();
}
+void overridePropertiesFromCommandLine(const argparse::ArgumentParser& parser,
const std::shared_ptr<minifi::Configure>& configure) {
+ const auto& properties = parser.get<std::vector<std::string>>("--property");
+ for (const auto& property : properties) {
+ auto property_key_and_value =
utils::StringUtils::splitAndTrimRemovingEmpty(property, "=");
+ if (property_key_and_value.size() != 2) {
+ std::cerr << "Command line property must be defined in <key>=<value>
format, invalid property: " << property << std::endl;
+ std::cerr << parser;
+ std::exit(1);
+ }
+ configure->set(property_key_and_value[0], property_key_and_value[1]);
+ }
+}
+
+void dumpDocsIfRequested(const argparse::ArgumentParser& parser, const
std::shared_ptr<minifi::Configure>& configure) {
+ if (!parser.is_used("--docs")) {
+ return;
+ }
+ const auto& docs_params = parser.get<std::vector<std::string>>("--docs");
+ if (utils::file::create_dir(docs_params[0]) != 0) {
+ std::cerr << "Working directory doesn't exist and cannot be created: " <<
docs_params[0] << std::endl;
+ exit(1);
Review Comment:
Updated in 8e64616285aa944ae5e35bece9c07b025f737577
##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -134,7 +135,93 @@ void writeJsonSchema(const
std::shared_ptr<minifi::Configure> &configuration, st
out << minifi::docs::generateJsonSchema();
}
+void overridePropertiesFromCommandLine(const argparse::ArgumentParser& parser,
const std::shared_ptr<minifi::Configure>& configure) {
+ const auto& properties = parser.get<std::vector<std::string>>("--property");
+ for (const auto& property : properties) {
+ auto property_key_and_value =
utils::StringUtils::splitAndTrimRemovingEmpty(property, "=");
+ if (property_key_and_value.size() != 2) {
+ std::cerr << "Command line property must be defined in <key>=<value>
format, invalid property: " << property << std::endl;
+ std::cerr << parser;
+ std::exit(1);
+ }
+ configure->set(property_key_and_value[0], property_key_and_value[1]);
+ }
+}
+
+void dumpDocsIfRequested(const argparse::ArgumentParser& parser, const
std::shared_ptr<minifi::Configure>& configure) {
+ if (!parser.is_used("--docs")) {
+ return;
+ }
+ const auto& docs_params = parser.get<std::vector<std::string>>("--docs");
+ if (utils::file::create_dir(docs_params[0]) != 0) {
+ std::cerr << "Working directory doesn't exist and cannot be created: " <<
docs_params[0] << std::endl;
+ exit(1);
+ }
+
+ std::cout << "Dumping docs to " << docs_params[0] << std::endl;
+ if (docs_params.size() > 1) {
+ auto path = std::filesystem::path(docs_params[1]);
+ if (std::filesystem::exists(path) &&
!std::filesystem::is_regular_file(path)) {
+ std::cerr << "PROCESSORS.md target path exists, but it is not a regular
file: " << path << std::endl;
+ exit(1);
+ }
+ auto dir = path.parent_path();
+ if (dir == docs_params[0]) {
+ std::cerr << "Target file should be out of the working directory: " <<
dir << std::endl;
+ exit(1);
+ }
+ std::ofstream outref(docs_params[1]);
+ dumpDocs(configure, docs_params[0], outref);
+ } else {
+ dumpDocs(configure, docs_params[0], std::cout);
+ }
+ exit(0);
+}
+
+void writeSchemaIfRequested(const argparse::ArgumentParser& parser, const
std::shared_ptr<minifi::Configure>& configure) {
+ if (!parser.is_used("--schema")) {
+ return;
+ }
+ const auto& schema_path = parser.get("--schema");
+ if (std::filesystem::exists(schema_path) &&
!std::filesystem::is_regular_file(schema_path)) {
+ std::cerr << "JSON schema target path already exists, but it is not a
regular file: " << schema_path << std::endl;
+ exit(1);
+ }
+
+ auto parent_dir = std::filesystem::path(schema_path).parent_path();
+ if (utils::file::create_dir(parent_dir) != 0) {
+ std::cerr << "JSON schema parent directory doesn't exist and cannot be
created: " << parent_dir << std::endl;
+ exit(1);
+ }
+ std::cout << "Writing json schema to " << schema_path << std::endl;
+ std::ofstream schema_file{schema_path};
+ writeJsonSchema(configure, schema_file);
+ std::exit(0);
Review Comment:
Updated in 8e64616285aa944ae5e35bece9c07b025f737577
--
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]