--- a/src/CLIParser.h Tue May 11 18:30:50 2021 +0200
+++ b/src/CLIParser.h Tue May 11 20:42:22 2021 +0200
@@ -36,8 +36,28 @@
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);
+ }
+
+ RelationConfiguration::ENTITY parseEntity(const relpipe::common::type::StringX& value) {
+ if (value == L"relation") return RelationConfiguration::ENTITY::RELATION;
+ else if (value == L"attribute") return RelationConfiguration::ENTITY::ATTRIBUTE;
+ else if (value == L"value") return RelationConfiguration::ENTITY::VALUE;
+ else throw relpipe::cli::RelpipeCLIException(L"Unable to parse entity value: " + value + L" (expecting „relation“, „attribute“ or „value“)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
+ }
+
void addRelation(Configuration& c, RelationConfiguration& currentRelation) {
if (currentRelation.relation.size()) {
+ using E = RelationConfiguration::ENTITY;
+ currentRelation.relationPattern = currentRelation.caseSensitive[E::RELATION] ? std::wregex(currentRelation.relation) : std::wregex(currentRelation.relation, std::regex_constants::icase);
+ currentRelation.attributePattern = currentRelation.caseSensitive[E::ATTRIBUTE] ? std::wregex(currentRelation.attribute) : std::wregex(currentRelation.attribute, std::regex_constants::icase);
+ currentRelation.valuePattern = currentRelation.caseSensitive[E::VALUE] ? std::wregex(currentRelation.value) : std::wregex(currentRelation.value, std::regex_constants::icase);
c.relationConfigurations.push_back(currentRelation);
currentRelation = RelationConfiguration();
}
@@ -48,6 +68,8 @@
static const relpipe::common::type::StringX OPTION_RELATION;
static const relpipe::common::type::StringX OPTION_ATTRIBUTE;
static const relpipe::common::type::StringX OPTION_PATTERN;
+ static const relpipe::common::type::StringX OPTION_CASE_SENSITIVE;
+ static const relpipe::common::type::StringX OPTION_INVERT_MATCH;
Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
Configuration c;
@@ -59,11 +81,16 @@
if (option == OPTION_RELATION) {
addRelation(c, currentRelation); // previous relation
currentRelation.relation = readNext(arguments, i);
- currentRelation.relationPattern = std::wregex(currentRelation.relation);
} else if (option == OPTION_ATTRIBUTE) {
- currentRelation.attributePattern = std::wregex(readNext(arguments, i));
+ currentRelation.attribute = readNext(arguments, i);
} else if (option == OPTION_PATTERN) {
- currentRelation.valuePattern = std::wregex(readNext(arguments, i));
+ currentRelation.value = readNext(arguments, i);
+ } else if (option == OPTION_CASE_SENSITIVE) {
+ RelationConfiguration::ENTITY entity = parseEntity(readNext(arguments, i));
+ currentRelation.caseSensitive[entity] = parseBoolean(readNext(arguments, i));
+ } else if (option == OPTION_INVERT_MATCH) {
+ RelationConfiguration::ENTITY entity = parseEntity(readNext(arguments, i));
+ currentRelation.invertMatch[entity] = parseBoolean(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
@@ -78,6 +105,8 @@
const relpipe::common::type::StringX CLIParser::OPTION_RELATION = L"--relation";
const relpipe::common::type::StringX CLIParser::OPTION_ATTRIBUTE = L"--attribute";
const relpipe::common::type::StringX CLIParser::OPTION_PATTERN = L"--pattern";
+const relpipe::common::type::StringX CLIParser::OPTION_CASE_SENSITIVE = L"--case-sensitive";
+const relpipe::common::type::StringX CLIParser::OPTION_INVERT_MATCH = L"--invert-match";
}
}