--- a/src/CLIParser.h Thu Apr 07 21:06:37 2022 +0200
+++ b/src/CLIParser.h Thu Apr 07 23:04:12 2022 +0200
@@ -36,76 +36,20 @@
else throw relpipe::cli::RelpipeCLIException(L"Missing CLI argument" + (i > 0 ? (L" after " + arguments[i - 1]) : L""), relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
- /**
- * TODO: use a common method
- */
- bool parseBoolean(const relpipe::common::type::StringX& value) {
- if (value == L"true") return true;
- else if (value == L"false") return false;
- else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
- }
-
- void addRelation(Configuration& c, RelationConfiguration& currentRelation) {
- if (currentRelation.relation.size()) {
- c.relationConfigurations.push_back(currentRelation);
- currentRelation = RelationConfiguration();
- }
- }
-
- /**
- * TODO: use a common method
- */
- relpipe::writer::TypeId parseTypeId(const relpipe::common::type::StringX& value) {
- using t = relpipe::writer::TypeId;
- if (value == L"string") return t::STRING;
- else if (value == L"integer") return t::INTEGER;
- else if (value == L"boolean") return t::BOOLEAN;
- else throw relpipe::cli::RelpipeCLIException(L"Unable to parse TypeId: " + value, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
- }
-
public:
- static const relpipe::common::type::StringX OPTION_NAMESPACE;
- static const relpipe::common::type::StringX OPTION_RELATION;
- static const relpipe::common::type::StringX OPTION_WHERE;
- static const relpipe::common::type::StringX OPTION_INPUT_ATTRIBUTES;
- static const relpipe::common::type::StringX OPTION_OUTPUT_ATTRIBUTE;
- static const relpipe::common::type::StringX OPTION_XML_ATTRIBUTE;
+ static const relpipe::common::type::StringX OPTION_TCP_PORT;
Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
Configuration c;
- RelationConfiguration currentRelation;
for (int i = 0; i < arguments.size();) {
relpipe::common::type::StringX option = readNext(arguments, i);
- if (option == OPTION_NAMESPACE) {
- c.namespaceMappings.push_back(readNext(arguments, i));
- c.namespaceMappings.push_back(readNext(arguments, i));
- } else if (option == OPTION_RELATION) {
- addRelation(c, currentRelation); // previous relation
- currentRelation.relation = readNext(arguments, i);
- } else if (option == OPTION_WHERE) {
- currentRelation.where = readNext(arguments, i);
- } else if (option == OPTION_XML_ATTRIBUTE) {
- currentRelation.xmlAttributes.push_back(readNext(arguments, i));
- } else if (option == OPTION_OUTPUT_ATTRIBUTE) {
- AttributeRecipe attribute;
- attribute.name = readNext(arguments, i);
- attribute.type = parseTypeId(readNext(arguments, i));
- attribute.httpd = readNext(arguments, i);
- currentRelation.outputAttributes.push_back(attribute);
- } else if (option == OPTION_INPUT_ATTRIBUTES) {
- relpipe::common::type::StringX policyName = readNext(arguments, i);
- InputAttributePolicy policy;
- if (policyName == L"append") policy = InputAttributePolicy::Append;
- else if (policyName == L"prepend") policy = InputAttributePolicy::Prepend;
- else if (policyName == L"auto") policy = InputAttributePolicy::Auto;
- else throw relpipe::cli::RelpipeCLIException(L"Unsupported input attributes policy: " + policyName, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
- currentRelation.inputAttributePolicy = policy;
+ if (option == OPTION_TCP_PORT) {
+ c.tcpPort = stoi(readNext(arguments, i));
} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
}
- addRelation(c, currentRelation); // last relation
return c;
}
@@ -114,12 +58,7 @@
}
};
-const relpipe::common::type::StringX CLIParser::OPTION_NAMESPACE = L"--namespace";
-const relpipe::common::type::StringX CLIParser::OPTION_RELATION = L"--relation";
-const relpipe::common::type::StringX CLIParser::OPTION_WHERE = L"--where";
-const relpipe::common::type::StringX CLIParser::OPTION_INPUT_ATTRIBUTES = L"--input-attributes";
-const relpipe::common::type::StringX CLIParser::OPTION_OUTPUT_ATTRIBUTE = L"--output-attribute";
-const relpipe::common::type::StringX CLIParser::OPTION_XML_ATTRIBUTE = L"--xml-attribute";
+const relpipe::common::type::StringX CLIParser::OPTION_TCP_PORT = L"--tcp-port";
}
}