author | František Kučera <franta-hg@frantovo.cz> |
Sun, 16 May 2021 17:33:35 +0200 | |
branch | v_0 |
changeset 26 | 576d4965434f |
parent 25 | 0cfbaf5c57a6 |
permissions | -rw-r--r-- |
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 |
|
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
55 |
ENTITY parseModifyTarget(const relpipe::common::type::StringX& value) { |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
56 |
if (value == L"relation-name") return ENTITY::RELATION; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
57 |
else if (value == L"attribute-name") return ENTITY::ATTRIBUTE; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
58 |
else if (value == L"value") return ENTITY::VALUE; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
59 |
else throw relpipe::cli::RelpipeCLIException(L"Unable to parse entity value: " + value + L" (expecting „relation-name“, „attribute-name“ or „value“)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
60 |
} |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
61 |
|
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
|
62 |
void addRule(RelationConfiguration& currentRelation, RewriteRule& currentRule) { |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
63 |
if (currentRule.modify != ENTITY::DEFAULT) { |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
64 |
// the --value is optional → set defaults if missing: |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
65 |
if (currentRule.modify == ENTITY::RELATION && currentRule.value.size() == 0) currentRule.value = currentRelation.relation; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
66 |
if (currentRule.modify == ENTITY::ATTRIBUTE && currentRule.value.size() == 0) currentRule.value = currentRule.attribute; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
67 |
|
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
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 |
} |
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 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
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 |
} |
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 |
|
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 |
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
|
85 |
|
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 |
static const relpipe::common::type::StringX OPTION_RELATION; |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
87 |
static const relpipe::common::type::StringX OPTION_MODIFY; |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
|
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 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
|
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 |
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
|
100 |
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
|
101 |
|
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 |
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
|
103 |
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
|
104 |
currentRelation.relation = readNext(arguments, i); |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
105 |
} else if (option == OPTION_MODIFY) { |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
106 |
addRule(currentRelation, currentRule); // previous rule |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
107 |
currentRule.modify = parseModifyTarget(readNext(arguments, i)); |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
108 |
if (currentRule.modify == ENTITY::VALUE) currentRule.modify = ENTITY::DEFAULT; |
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
|
109 |
} else if (option == OPTION_ATTRIBUTE) { |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
110 |
if (currentRule.modify == ENTITY::DEFAULT) { |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
111 |
currentRule.modify = ENTITY::VALUE; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
112 |
} else if (currentRule.modify == ENTITY::VALUE) { |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
113 |
addRule(currentRelation, currentRule); // previous rule |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
114 |
currentRule.modify = ENTITY::VALUE; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
115 |
} |
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
|
116 |
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
|
117 |
} 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
|
118 |
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
|
119 |
} 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
|
120 |
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
|
121 |
} 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
|
122 |
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
|
123 |
bool value = parseBoolean(readNext(arguments, i)); |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
124 |
if (currentRule.modify == ENTITY::DEFAULT) currentRelation.caseSensitive[entity] = value; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
125 |
currentRule.caseSensitive[entity] = value; |
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
|
126 |
} 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
|
127 |
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
|
128 |
bool value = parseBoolean(readNext(arguments, i)); |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
129 |
if (currentRule.modify == ENTITY::DEFAULT) currentRelation.invertMatch[entity] = value; |
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
130 |
currentRule.invertMatch[entity] = value; |
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
|
131 |
} 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
|
132 |
} |
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
|
133 |
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
|
134 |
|
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
|
135 |
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
|
136 |
} |
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
|
137 |
|
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
|
138 |
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
|
139 |
} |
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
|
140 |
}; |
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
|
141 |
|
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
|
142 |
const relpipe::common::type::StringX CLIParser::OPTION_RELATION = L"--relation"; |
26
576d4965434f
new CLI interface: --modify relation-name, --modify attribute-name
František Kučera <franta-hg@frantovo.cz>
parents:
25
diff
changeset
|
143 |
const relpipe::common::type::StringX CLIParser::OPTION_MODIFY = L"--modify"; |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
|
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
|
150 |
} |
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
|
151 |
} |
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
|
152 |
} |