equal
deleted
inserted
replaced
34 string_t readNext(std::vector<string_t> arguments, int& i) { |
34 string_t readNext(std::vector<string_t> arguments, int& i) { |
35 if (i < arguments.size()) return arguments[i++]; |
35 if (i < arguments.size()) return arguments[i++]; |
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); |
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); |
37 } |
37 } |
38 |
38 |
|
39 /** |
|
40 * TODO: use a common method |
|
41 */ |
|
42 bool parseBoolean(const string_t& value) { |
|
43 if (value == L"true") return true; |
|
44 else if (value == L"false") return false; |
|
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); |
|
46 } |
|
47 |
39 void addRelation(Configuration& c, RelationConfiguration& currentRelation) { |
48 void addRelation(Configuration& c, RelationConfiguration& currentRelation) { |
40 if (currentRelation.relation.size()) { |
49 if (currentRelation.relation.size()) { |
41 c.relationConfigurations.push_back(currentRelation); |
50 c.relationConfigurations.push_back(currentRelation); |
42 currentRelation = RelationConfiguration(); |
51 currentRelation = RelationConfiguration(); |
43 } |
52 } |
56 static const string_t OPTION_NAMESPACE; |
65 static const string_t OPTION_NAMESPACE; |
57 static const string_t OPTION_RELATION; |
66 static const string_t OPTION_RELATION; |
58 static const string_t OPTION_NAME_IS_XPATH; |
67 static const string_t OPTION_NAME_IS_XPATH; |
59 static const string_t OPTION_RECORDS; |
68 static const string_t OPTION_RECORDS; |
60 static const string_t OPTION_ATTRIBUTE; |
69 static const string_t OPTION_ATTRIBUTE; |
|
70 static const string_t OPTION_XINCLUDE; |
61 |
71 |
62 Configuration parse(const std::vector<string_t>& arguments) { |
72 Configuration parse(const std::vector<string_t>& arguments) { |
63 Configuration c; |
73 Configuration c; |
64 RelationConfiguration currentRelation; |
74 RelationConfiguration currentRelation; |
65 |
75 |
67 string_t option = readNext(arguments, i); |
77 string_t option = readNext(arguments, i); |
68 |
78 |
69 if (option == OPTION_NAMESPACE) { |
79 if (option == OPTION_NAMESPACE) { |
70 c.namespaceMappings.push_back(readNext(arguments, i)); |
80 c.namespaceMappings.push_back(readNext(arguments, i)); |
71 c.namespaceMappings.push_back(readNext(arguments, i)); |
81 c.namespaceMappings.push_back(readNext(arguments, i)); |
|
82 } else if (option == OPTION_XINCLUDE) { |
|
83 c.xinclude = parseBoolean(readNext(arguments, i)); |
72 } else if (option == OPTION_RELATION) { |
84 } else if (option == OPTION_RELATION) { |
73 addRelation(c, currentRelation); // previous relation |
85 addRelation(c, currentRelation); // previous relation |
74 currentRelation.relation = readNext(arguments, i); |
86 currentRelation.relation = readNext(arguments, i); |
75 } else if (option == OPTION_NAME_IS_XPATH) { |
87 } else if (option == OPTION_NAME_IS_XPATH) { |
76 currentRelation.nameIsXPath = true; |
88 currentRelation.nameIsXPath = true; |
96 const string_t CLIParser::OPTION_NAMESPACE = L"--namespace"; |
108 const string_t CLIParser::OPTION_NAMESPACE = L"--namespace"; |
97 const string_t CLIParser::OPTION_RELATION = L"--relation"; |
109 const string_t CLIParser::OPTION_RELATION = L"--relation"; |
98 const string_t CLIParser::OPTION_NAME_IS_XPATH = L"--name-is-xpath"; |
110 const string_t CLIParser::OPTION_NAME_IS_XPATH = L"--name-is-xpath"; |
99 const string_t CLIParser::OPTION_RECORDS = L"--records"; |
111 const string_t CLIParser::OPTION_RECORDS = L"--records"; |
100 const string_t CLIParser::OPTION_ATTRIBUTE = L"--attribute"; |
112 const string_t CLIParser::OPTION_ATTRIBUTE = L"--attribute"; |
|
113 const string_t CLIParser::OPTION_XINCLUDE = L"--xinclude"; |
101 |
114 |
102 } |
115 } |
103 } |
116 } |
104 } |
117 } |