src/CLIParser.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 15 May 2021 18:18:10 +0200
branchv_0
changeset 25 0cfbaf5c57a6
child 26 576d4965434f
permissions -rw-r--r--
new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#pragma once
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <vector>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/common/type/typedefs.h>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/CLI.h>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/cli/RelpipeCLIException.h>
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include "Configuration.h"
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
namespace relpipe {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
namespace tr {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
namespace sed {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
class CLIParser {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
private:
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	relpipe::common::type::StringX readNext(std::vector<relpipe::common::type::StringX> arguments, int& i) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		if (i < arguments.size()) return arguments[i++];
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		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);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	/**
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	 * TODO: use a common method
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	 */
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	bool parseBoolean(const relpipe::common::type::StringX& value) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		if (value == L"true") return true;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		else if (value == L"false") return false;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		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);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	ENTITY parseEntity(const relpipe::common::type::StringX& value) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		if (value == L"relation") return ENTITY::RELATION;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		else if (value == L"attribute") return ENTITY::ATTRIBUTE;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		else if (value == L"value") return ENTITY::VALUE;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		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);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	void addRule(RelationConfiguration& currentRelation, RewriteRule& currentRule) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		if (currentRule.attribute.size()) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
			currentRule.attributePattern = currentRule.caseSensitive[ENTITY::ATTRIBUTE] ? std::wregex(currentRule.attribute) : std::wregex(currentRule.attribute, std::regex_constants::icase);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
			currentRule.valuePattern = currentRule.caseSensitive[ENTITY::VALUE] ? std::wregex(currentRule.value) : std::wregex(currentRule.value, std::regex_constants::icase);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
			currentRelation.rules.push_back(currentRule);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
			currentRule = RewriteRule(currentRelation.caseSensitive, currentRelation.invertMatch);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	void addRelation(Configuration& c, RelationConfiguration& currentRelation, RewriteRule& currentRule) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		if (currentRelation.relation.size()) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
			currentRelation.relationPattern = currentRelation.caseSensitive[ENTITY::RELATION] ? std::wregex(currentRelation.relation) : std::wregex(currentRelation.relation, std::regex_constants::icase);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
			addRule(currentRelation, currentRule); // last rule
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
			c.relationConfigurations.push_back(currentRelation);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
			currentRelation = RelationConfiguration();
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
public:
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	static const relpipe::common::type::StringX OPTION_RELATION;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	static const relpipe::common::type::StringX OPTION_ATTRIBUTE;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	static const relpipe::common::type::StringX OPTION_VALUE;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
	static const relpipe::common::type::StringX OPTION_REPLACEMENT;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	static const relpipe::common::type::StringX OPTION_CASE_SENSITIVE;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
	static const relpipe::common::type::StringX OPTION_INVERT_MATCH;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
		Configuration c;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		RelationConfiguration currentRelation;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		RewriteRule currentRule(currentRelation.caseSensitive, currentRelation.invertMatch);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
		for (int i = 0; i < arguments.size();) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
			relpipe::common::type::StringX option = readNext(arguments, i);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
			if (option == OPTION_RELATION) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
				addRelation(c, currentRelation, currentRule); // previous relation
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
				currentRelation.relation = readNext(arguments, i);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
			} else if (option == OPTION_ATTRIBUTE) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
				addRule(currentRelation, currentRule); // previous rule
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
				currentRule.attribute = readNext(arguments, i);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
			} else if (option == OPTION_VALUE) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
				currentRule.value = readNext(arguments, i);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
			} else if (option == OPTION_REPLACEMENT) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
				currentRule.replacement = readNext(arguments, i);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
			} else if (option == OPTION_CASE_SENSITIVE) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
				ENTITY entity = parseEntity(readNext(arguments, i));
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
				bool value = parseBoolean(readNext(arguments, i));
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
				if (currentRule.attribute.size()) currentRule.caseSensitive[entity] = value;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
				else currentRelation.caseSensitive[entity] = value;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
			} else if (option == OPTION_INVERT_MATCH) {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
				ENTITY entity = parseEntity(readNext(arguments, i));
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
				bool value = parseBoolean(readNext(arguments, i));
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
				if (currentRule.attribute.size()) currentRule.invertMatch[entity] = value;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   109
				else currentRelation.invertMatch[entity] = value;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   110
			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   111
		}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   112
		addRelation(c, currentRelation, currentRule); // last relation
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
		return c;
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
	virtual ~CLIParser() {
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
	}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
};
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
const relpipe::common::type::StringX CLIParser::OPTION_RELATION = L"--relation";
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
const relpipe::common::type::StringX CLIParser::OPTION_ATTRIBUTE = L"--attribute";
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
const relpipe::common::type::StringX CLIParser::OPTION_VALUE = L"--value";
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
const relpipe::common::type::StringX CLIParser::OPTION_REPLACEMENT = L"--replacement";
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   125
const relpipe::common::type::StringX CLIParser::OPTION_CASE_SENSITIVE = L"--case-sensitive";
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
const relpipe::common::type::StringX CLIParser::OPTION_INVERT_MATCH = L"--invert-match";
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   128
}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   129
}
0cfbaf5c57a6 new CLI interface: --relation --attribute --value --replacement --case-sensitive --invert-match – first version
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   130
}